@@ -42,18 +42,34 @@ if (env.stringified['process.env'].NODE_ENV !== '"production"') {
42
42
throw new Error ( 'Production builds must have NODE_ENV=production.' ) ;
43
43
}
44
44
45
- // Note: defined here because it will be used more than once.
45
+ // Create two seperate files for css and cssmodules this allow for
46
+ // different settings to be used with ExtractTextPlugin.
46
47
const cssFilename = 'static/css/[name].[contenthash:8].css' ;
48
+ const cssModulesFilename = 'static/css/[name]-cssmodules.[contenthash:8].css' ;
47
49
48
50
// ExtractTextPlugin expects the build output to be flat.
49
51
// (See https://github.com/webpack-contrib/extract-text-webpack-plugin/issues/27)
50
52
// However, our output is structured with css, js and media folders.
51
53
// To have this structure working with relative paths, we have to use custom options.
52
- const extractTextPluginOptions = shouldUseRelativeAssetPaths
54
+ const extractTextPluginCSSOptions = shouldUseRelativeAssetPaths
53
55
? // Making sure that the publicPath goes back to to build folder.
54
- { publicPath : Array ( cssFilename . split ( '/' ) . length ) . join ( '../' ) }
56
+ { publicPath : Array ( cssFilename . split ( '/' ) . length ) . join ( '../' ) }
55
57
: { } ;
56
58
59
+ const extractTextPluginCSSModulesOptions = shouldUseRelativeAssetPaths
60
+ ? // Making sure that the publicPath goes back to to build folder.
61
+ { publicPath : Array ( cssModulesFilename . split ( '/' ) . length ) . join ( '../' ) }
62
+ : { } ;
63
+
64
+ const ExtractTextPluginCSS = new ExtractTextPlugin ( {
65
+ filename : cssFilename ,
66
+ } )
67
+
68
+ const ExtractTextPluginCSSModules = new ExtractTextPlugin ( {
69
+ filename : cssModulesFilename ,
70
+ ignoreOrder : true ,
71
+ } )
72
+
57
73
// This is the production configuration.
58
74
// It compiles slowly and is focused on producing a fast and minimal bundle.
59
75
// The development configuration is different and lives in a separate file.
@@ -96,7 +112,7 @@ module.exports = {
96
112
// https://github.com/facebookincubator/create-react-app/issues/290
97
113
// `web` extension prefixes have been added for better support
98
114
// for React Native Web.
99
- extensions : [ '.web.js' , '.js' , '.json' , '.web.jsx' , '.jsx' ] ,
115
+ extensions : [ '.web.js' , '.mjs' , '. js', '.json' , '.web.jsx' , '.jsx' ] ,
100
116
alias : {
101
117
// @remove -on-eject-begin
102
118
// Resolve Babel runtime relative to react-scripts.
@@ -130,7 +146,7 @@ module.exports = {
130
146
// First, run the linter.
131
147
// It's important to do this before Babel processes the JS.
132
148
{
133
- test : / \. ( j s | j s x ) $ / ,
149
+ test : / \. ( j s | j s x | m j s ) $ / ,
134
150
enforce : 'pre' ,
135
151
use : [
136
152
{
@@ -169,7 +185,7 @@ module.exports = {
169
185
} ,
170
186
// Process JS with Babel.
171
187
{
172
- test : / \. ( j s | j s x ) $ / ,
188
+ test : / \. ( j s | j s x | m j s ) $ / ,
173
189
include : paths . appSrc ,
174
190
loader : require . resolve ( 'babel-loader' ) ,
175
191
options : {
@@ -194,7 +210,7 @@ module.exports = {
194
210
// in the main CSS file.
195
211
{
196
212
test : / \. m o d u l e .c s s $ / ,
197
- loader : ExtractTextPlugin . extract (
213
+ loader : ExtractTextPluginCSSModules . extract (
198
214
Object . assign (
199
215
{
200
216
fallback : require . resolve ( 'style-loader' ) ,
@@ -204,7 +220,7 @@ module.exports = {
204
220
options : {
205
221
importLoaders : 1 ,
206
222
modules : true ,
207
- localIdentName : '[path][name]__ [local]' ,
223
+ localIdentName : '[path]__ [name]___ [local]' ,
208
224
minimize : true ,
209
225
sourceMap : shouldUseSourceMap ,
210
226
} ,
@@ -231,18 +247,23 @@ module.exports = {
231
247
} ,
232
248
] ,
233
249
} ,
234
- extractTextPluginOptions
250
+ extractTextPluginCSSModulesOptions
235
251
)
236
252
) ,
237
- // Note: this won't work without `new ExtractTextPlugin() ` in `plugins`.
253
+ // Note: this won't work without `ExtractTextPluginCSSModules ` in `plugins`.
238
254
} ,
239
255
{
240
256
test : / \. c s s $ / ,
241
257
exclude : / \. m o d u l e \. c s s $ / ,
242
- loader : ExtractTextPlugin . extract (
258
+ loader : ExtractTextPluginCSS . extract (
243
259
Object . assign (
244
260
{
245
- fallback : require . resolve ( 'style-loader' ) ,
261
+ fallback : {
262
+ loader : require . resolve ( 'style-loader' ) ,
263
+ options : {
264
+ hmr : false ,
265
+ } ,
266
+ } ,
246
267
use : [
247
268
{
248
269
loader : require . resolve ( 'css-loader' ) ,
@@ -274,10 +295,10 @@ module.exports = {
274
295
} ,
275
296
] ,
276
297
} ,
277
- extractTextPluginOptions
298
+ extractTextPluginCSSOptions
278
299
)
279
300
) ,
280
- // Note: this won't work without `new ExtractTextPlugin() ` in `plugins`.
301
+ // Note: this won't work without `ExtractTextPluginCSS ` in `plugins`.
281
302
} ,
282
303
// "file" loader makes sure assets end up in the `build` folder.
283
304
// When you `import` an asset, you get its filename.
@@ -339,6 +360,9 @@ module.exports = {
339
360
// https://github.com/mishoo/UglifyJS2/issues/2011
340
361
comparisons : false ,
341
362
} ,
363
+ mangle : {
364
+ safari10 : true ,
365
+ } ,
342
366
output : {
343
367
comments : false ,
344
368
// Turned on because emoji and regex is not minified properly using default
@@ -348,10 +372,10 @@ module.exports = {
348
372
sourceMap : shouldUseSourceMap ,
349
373
} ) ,
350
374
// Note: this won't work without ExtractTextPlugin.extract(..) in `loaders`.
351
- new ExtractTextPlugin ( {
352
- filename : cssFilename ,
353
- ignoreOrder : true ,
354
- } ) ,
375
+ // We have two ExtractTextPlugins to allow for different settings for
376
+ // cssmodules and regular css
377
+ ExtractTextPluginCSS ,
378
+ ExtractTextPluginCSSModules ,
355
379
// Generate a manifest file which contains a mapping of all asset filenames
356
380
// to their corresponding output file so that tools can pick it up without
357
381
// having to parse `index.html`.
0 commit comments