@@ -9,7 +9,7 @@ import { getOptions } from 'loader-utils';
9
9
import validateOptions from 'schema-utils' ;
10
10
11
11
import postcss from 'postcss' ;
12
- // TODO(michael-ciniawsky)
12
+ // TODO(michael-ciniawsky)
13
13
// replace with postcss-icss-{url, import}
14
14
import urls from './plugins/url' ;
15
15
import imports from './plugins/import' ;
@@ -26,13 +26,9 @@ const DEFAULTS = {
26
26
sourceMap : false ,
27
27
} ;
28
28
29
- export default function loader ( css , map , meta ) {
29
+ export default function loader ( css , map , meta ) {
30
30
// Loader Options
31
- const options = Object . assign (
32
- { } ,
33
- DEFAULTS ,
34
- getOptions ( this )
35
- ) ;
31
+ const options = Object . assign ( { } , DEFAULTS , getOptions ( this ) ) ;
36
32
37
33
validateOptions ( schema , options , 'CSS Loader' ) ;
38
34
@@ -52,9 +48,8 @@ export default function loader (css, map, meta) {
52
48
53
49
// URL Plugin
54
50
if ( options . url ) {
55
- plugins . push ( urls ( ) ) ;
51
+ plugins . push ( urls ( options ) ) ;
56
52
}
57
-
58
53
59
54
// Import Plugin
60
55
if ( options . import ) {
@@ -65,7 +60,7 @@ export default function loader (css, map, meta) {
65
60
if ( options . minimize ) {
66
61
plugins . push ( minifier ( ) ) ;
67
62
}
68
-
63
+
69
64
if ( meta ) {
70
65
const { ast } = meta ;
71
66
// Reuse CSS AST (PostCSS AST e.g 'postcss-loader')
@@ -74,34 +69,33 @@ export default function loader (css, map, meta) {
74
69
css = ast . root ;
75
70
}
76
71
}
77
-
78
- map = options . sourceMap
72
+
73
+ map = options . sourceMap
79
74
? {
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
+
87
82
return postcss ( plugins )
88
83
. process ( css , {
89
84
from : `/css-loader!${ file } ` ,
90
85
map,
91
86
to : file ,
92
- } ) . then ( ( { css, map, messages } ) => {
87
+ } )
88
+ . then ( ( { css, map, messages } ) => {
93
89
if ( meta && meta . messages ) {
94
- messages = messages . concat ( meta . messages )
90
+ messages = messages . concat ( meta . messages ) ;
95
91
}
96
-
92
+
97
93
// CSS Imports
98
94
const imports = messages
99
- . filter ( ( msg ) => msg . type === 'import' ? msg : false )
95
+ . filter ( ( msg ) => ( msg . type === 'import' ? msg : false ) )
100
96
. reduce ( ( imports , msg ) => {
101
97
try {
102
- msg = typeof msg . import === 'function'
103
- ? msg . import ( )
104
- : msg . import ;
98
+ msg = typeof msg . import === 'function' ? msg . import ( ) : msg . import ;
105
99
106
100
imports += msg ;
107
101
} catch ( err ) {
@@ -110,17 +104,15 @@ export default function loader (css, map, meta) {
110
104
this . emitError ( err ) ;
111
105
}
112
106
113
- return imports
114
- } , '' )
115
-
107
+ return imports ;
108
+ } , '' ) ;
109
+
116
110
// CSS Exports
117
111
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 ;
124
116
125
117
exports += msg ;
126
118
} catch ( err ) {
@@ -130,23 +122,27 @@ export default function loader (css, map, meta) {
130
122
}
131
123
132
124
return exports ;
133
- } , '' )
134
-
135
- // TODO(michael-ciniawsky)
125
+ } , '' ) ;
126
+
127
+ // TODO(michael-ciniawsky)
136
128
// triage if and add CSS runtime back
137
129
const result = [
138
130
imports ? `// CSS Imports\n${ imports } \n` : false ,
139
131
exports ? `// CSS Exports\n${ exports } \n` : false ,
140
- `// CSS\nexport default \`${ css } \``
132
+ `// CSS\nexport default \`${ css } \`` ,
141
133
]
142
134
. filter ( Boolean )
143
135
. join ( '\n' ) ;
144
-
136
+
145
137
cb ( null , result , map ? map . toJSON ( ) : null ) ;
146
138
147
139
return null ;
148
140
} )
149
141
. 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 ;
151
147
} ) ;
152
- } ;
148
+ }
0 commit comments