@@ -55,6 +55,20 @@ const extractTextPluginOptions = shouldUseRelativeAssetPaths
55
55
{ publicPath : Array ( cssFilename . split ( '/' ) . length ) . join ( '../' ) }
56
56
: { } ;
57
57
58
+ // Options for PostCSS as we reference these options twice
59
+ // Adds vendor prefixing to support IE9 and above
60
+ const postCSSLoaderOptions = {
61
+ // Necessary for external CSS imports to work
62
+ // https://github.com/facebookincubator/create-react-app/issues/2677
63
+ ident : 'postcss' ,
64
+ plugins : ( ) => [
65
+ require ( 'postcss-flexbugs-fixes' ) ,
66
+ autoprefixer ( {
67
+ flexbox : 'no-2009' ,
68
+ } ) ,
69
+ ] ,
70
+ } ;
71
+
58
72
// This is the production configuration.
59
73
// It compiles slowly and is focused on producing a fast and minimal bundle.
60
74
// The development configuration is different and lives in a separate file.
@@ -130,7 +144,7 @@ module.exports = {
130
144
// please link the files into your node_modules/ and let module-resolution kick in.
131
145
// Make sure your source files are compiled, as they will not be processed in any way.
132
146
new ModuleScopePlugin ( paths . appSrc , [ paths . appPackageJson ] ) ,
133
- new TsconfigPathsPlugin ( { configFile : paths . appTsConfig } )
147
+ new TsconfigPathsPlugin ( { configFile : paths . appTsConfig } ) ,
134
148
] ,
135
149
} ,
136
150
module : {
@@ -186,8 +200,10 @@ module.exports = {
186
200
// tags. If you use code splitting, however, any async bundles will still
187
201
// use the "style" loader inside the async code so CSS from them won't be
188
202
// in the main CSS file.
203
+ // By default we support CSS Modules with the extension .module.css
189
204
{
190
205
test : / \. c s s $ / ,
206
+ exclude : / \. m o d u l e \. c s s $ / ,
191
207
loader : ExtractTextPlugin . extract (
192
208
Object . assign (
193
209
{
@@ -208,24 +224,43 @@ module.exports = {
208
224
} ,
209
225
{
210
226
loader : require . resolve ( 'postcss-loader' ) ,
227
+ options : postCSSLoaderOptions ,
228
+ } ,
229
+ ] ,
230
+ } ,
231
+ extractTextPluginOptions
232
+ )
233
+ ) ,
234
+ // Note: this won't work without `new ExtractTextPlugin()` in `plugins`.
235
+ } ,
236
+ // Adds support for CSS Modules (https://github.com/css-modules/css-modules)
237
+ // using the extension .module.css
238
+ {
239
+ test : / \. m o d u l e \. c s s $ / ,
240
+ loader : ExtractTextPlugin . extract (
241
+ Object . assign (
242
+ {
243
+ fallback : {
244
+ loader : require . resolve ( 'style-loader' ) ,
245
+ options : {
246
+ hmr : false ,
247
+ } ,
248
+ } ,
249
+ use : [
250
+ {
251
+ loader : require . resolve ( 'css-loader' ) ,
211
252
options : {
212
- // Necessary for external CSS imports to work
213
- // https://github.com/facebookincubator/create-react-app/issues/2677
214
- ident : 'postcss' ,
215
- plugins : ( ) => [
216
- require ( 'postcss-flexbugs-fixes' ) ,
217
- autoprefixer ( {
218
- browsers : [
219
- '>1%' ,
220
- 'last 4 versions' ,
221
- 'Firefox ESR' ,
222
- 'not ie < 9' , // React doesn't support IE8 anyway
223
- ] ,
224
- flexbox : 'no-2009' ,
225
- } ) ,
226
- ] ,
253
+ importLoaders : 1 ,
254
+ minimize : true ,
255
+ sourceMap : shouldUseSourceMap ,
256
+ modules : true ,
257
+ localIdentName : '[path]__[name]___[local]' ,
227
258
} ,
228
259
} ,
260
+ {
261
+ loader : require . resolve ( 'postcss-loader' ) ,
262
+ options : postCSSLoaderOptions ,
263
+ } ,
229
264
] ,
230
265
} ,
231
266
extractTextPluginOptions
@@ -237,6 +272,7 @@ module.exports = {
237
272
// BIKO::START
238
273
{
239
274
test : / \. s c s s $ / ,
275
+ exclude : / \. m o d u l e \. s c s s $ / ,
240
276
loader : ExtractTextPlugin . extract (
241
277
Object . assign (
242
278
{
@@ -257,24 +293,47 @@ module.exports = {
257
293
} ,
258
294
{
259
295
loader : require . resolve ( 'postcss-loader' ) ,
296
+ options : postCSSLoaderOptions ,
297
+ } ,
298
+ {
299
+ loader : require . resolve ( 'sass-loader' ) ,
300
+ options : {
301
+ sourceMap : shouldUseSourceMap ,
302
+ } ,
303
+ } ,
304
+ ] ,
305
+ } ,
306
+ extractTextPluginOptions
307
+ )
308
+ ) ,
309
+ // Note: this won't work without `new ExtractTextPlugin()` in `plugins`.
310
+ } ,
311
+ {
312
+ test : / \. m o d u l e \. s c s s $ / ,
313
+ loader : ExtractTextPlugin . extract (
314
+ Object . assign (
315
+ {
316
+ fallback : {
317
+ loader : require . resolve ( 'style-loader' ) ,
318
+ options : {
319
+ hmr : false ,
320
+ } ,
321
+ } ,
322
+ use : [
323
+ {
324
+ loader : require . resolve ( 'css-loader' ) ,
260
325
options : {
261
- // Necessary for external CSS imports to work
262
- // https://github.com/facebookincubator/create-react-app/issues/2677
263
- ident : 'postcss' ,
264
- plugins : ( ) => [
265
- require ( 'postcss-flexbugs-fixes' ) ,
266
- autoprefixer ( {
267
- browsers : [
268
- '>1%' ,
269
- 'last 4 versions' ,
270
- 'Firefox ESR' ,
271
- 'not ie < 9' , // React doesn't support IE8 anyway
272
- ] ,
273
- flexbox : 'no-2009' ,
274
- } ) ,
275
- ] ,
326
+ importLoaders : 1 ,
327
+ minimize : true ,
328
+ sourceMap : shouldUseSourceMap ,
329
+ modules : true ,
330
+ localIdentName : '[path]__[name]___[local]' ,
276
331
} ,
277
332
} ,
333
+ {
334
+ loader : require . resolve ( 'postcss-loader' ) ,
335
+ options : postCSSLoaderOptions ,
336
+ } ,
278
337
{
279
338
loader : require . resolve ( 'sass-loader' ) ,
280
339
options : {
0 commit comments