1
1
/**
2
2
* @see https://webpack.github.io/docs/loaders.html
3
3
*/
4
- module . exports = function ( script ) {
5
- var content = this . exec ( script , __filename ) ;
6
- if ( ! content || content . length !== 1 ) {
7
- throw new Error ( 'The css-with-mapping-loader must be chained after the css-loader\n' + content ) ;
8
- }
4
+ module . exports = function ( ) { } ;
5
+
6
+ /**
7
+ * @see https://webpack.github.io/docs/loaders.html#pitching-loader
8
+ */
9
+ module . exports . pitch = function ( remainingRequest ) {
10
+ this . cacheable && this . cacheable ( ) ;
11
+
12
+ var loaderUtils = require ( 'loader-utils' ) ;
13
+ return encode . toString ( ) + '\n' +
14
+ 'var result = require(' + loaderUtils . stringifyRequest ( this , "!!" + remainingRequest ) + ');\n' +
15
+ 'if (typeof result === "string") {\n' +
16
+ 'module.exports = result;\n' +
17
+ '} else {\n' +
18
+ 'module.exports = encode(result);\n' +
19
+ '}\n' ;
20
+ } ;
21
+
22
+ function encode ( content ) {
9
23
var cssObject = content [ 0 ] ;
10
24
var cssContent = cssObject [ 1 ] || '' ;
11
25
var cssMapping = cssObject [ 3 ] ;
@@ -17,5 +31,5 @@ module.exports = function (script) {
17
31
var sourceURLs = cssMapping . sources . map ( function ( source ) {
18
32
return '/*# sourceURL=' + cssMapping . sourceRoot + source + ' */'
19
33
} ) ;
20
- return 'module.exports = ' + JSON . stringify ( [ cssContent ] . concat ( sourceURLs ) . concat ( [ sourceMapping ] ) . join ( '\n' ) ) ;
21
- } ;
34
+ return [ cssContent ] . concat ( sourceURLs ) . concat ( [ sourceMapping ] ) . join ( '\n' ) ;
35
+ }
0 commit comments