@@ -9,7 +9,7 @@ import { getOptions } from 'loader-utils';
99import validateOptions from 'schema-utils' ;
1010
1111import postcss from 'postcss' ;
12- // TODO(michael-ciniawsky)
12+ // TODO(michael-ciniawsky)
1313// replace with postcss-icss-{url, import}
1414import urls from './plugins/url' ;
1515import imports from './plugins/import' ;
@@ -26,13 +26,9 @@ const DEFAULTS = {
2626 sourceMap : false ,
2727} ;
2828
29- export default function loader ( css , map , meta ) {
29+ export default function loader ( css , map , meta ) {
3030 // Loader Options
31- const options = Object . assign (
32- { } ,
33- DEFAULTS ,
34- getOptions ( this )
35- ) ;
31+ const options = Object . assign ( { } , DEFAULTS , getOptions ( this ) ) ;
3632
3733 validateOptions ( schema , options , 'CSS Loader' ) ;
3834
@@ -52,9 +48,8 @@ export default function loader (css, map, meta) {
5248
5349 // URL Plugin
5450 if ( options . url ) {
55- plugins . push ( urls ( ) ) ;
51+ plugins . push ( urls ( options ) ) ;
5652 }
57-
5853
5954 // Import Plugin
6055 if ( options . import ) {
@@ -65,7 +60,7 @@ export default function loader (css, map, meta) {
6560 if ( options . minimize ) {
6661 plugins . push ( minifier ( ) ) ;
6762 }
68-
63+
6964 if ( meta ) {
7065 const { ast } = meta ;
7166 // Reuse CSS AST (PostCSS AST e.g 'postcss-loader')
@@ -74,34 +69,33 @@ export default function loader (css, map, meta) {
7469 css = ast . root ;
7570 }
7671 }
77-
78- map = options . sourceMap
72+
73+ map = options . sourceMap
7974 ? {
80- prev : map || false ,
81- inline : false ,
82- annotation : false ,
83- sourcesContent : true ,
84- }
85- : false
86-
75+ prev : map || false ,
76+ inline : false ,
77+ annotation : false ,
78+ sourcesContent : true ,
79+ }
80+ : false ;
81+
8782 return postcss ( plugins )
8883 . process ( css , {
8984 from : `/css-loader!${ file } ` ,
9085 map,
9186 to : file ,
92- } ) . then ( ( { css, map, messages } ) => {
87+ } )
88+ . then ( ( { css, map, messages } ) => {
9389 if ( meta && meta . messages ) {
94- messages = messages . concat ( meta . messages )
90+ messages = messages . concat ( meta . messages ) ;
9591 }
96-
92+
9793 // CSS Imports
9894 const imports = messages
99- . filter ( ( msg ) => msg . type === 'import' ? msg : false )
95+ . filter ( ( msg ) => ( msg . type === 'import' ? msg : false ) )
10096 . reduce ( ( imports , msg ) => {
10197 try {
102- msg = typeof msg . import === 'function'
103- ? msg . import ( )
104- : msg . import ;
98+ msg = typeof msg . import === 'function' ? msg . import ( ) : msg . import ;
10599
106100 imports += msg ;
107101 } catch ( err ) {
@@ -110,17 +104,15 @@ export default function loader (css, map, meta) {
110104 this . emitError ( err ) ;
111105 }
112106
113- return imports
114- } , '' )
115-
107+ return imports ;
108+ } , '' ) ;
109+
116110 // CSS Exports
117111 const exports = messages
118- . filter ( ( msg ) => msg . type === 'export' ? msg : false )
119- . reduce ( ( exports , msg ) => {
120- try {
121- msg = typeof msg . export === 'function'
122- ? msg . export ( )
123- : msg . export ;
112+ . filter ( ( msg ) => ( msg . type === 'export' ? msg : false ) )
113+ . reduce ( ( exports , msg ) => {
114+ try {
115+ msg = typeof msg . export === 'function' ? msg . export ( ) : msg . export ;
124116
125117 exports += msg ;
126118 } catch ( err ) {
@@ -130,23 +122,27 @@ export default function loader (css, map, meta) {
130122 }
131123
132124 return exports ;
133- } , '' )
134-
135- // TODO(michael-ciniawsky)
125+ } , '' ) ;
126+
127+ // TODO(michael-ciniawsky)
136128 // triage if and add CSS runtime back
137129 const result = [
138130 imports ? `// CSS Imports\n${ imports } \n` : false ,
139131 exports ? `// CSS Exports\n${ exports } \n` : false ,
140- `// CSS\nexport default \`${ css } \``
132+ `// CSS\nexport default \`${ css } \`` ,
141133 ]
142134 . filter ( Boolean )
143135 . join ( '\n' ) ;
144-
136+
145137 cb ( null , result , map ? map . toJSON ( ) : null ) ;
146138
147139 return null ;
148140 } )
149141 . catch ( ( err ) => {
150- err . name === 'CssSyntaxError' ? cb ( new SyntaxError ( err ) ) : cb ( err ) ;
142+ err = err . name === 'CssSyntaxError' ? new SyntaxError ( err ) : err ;
143+
144+ cb ( err ) ;
145+
146+ return null ;
151147 } ) ;
152- } ;
148+ }
0 commit comments