@@ -52,8 +52,8 @@ const cssFilename = 'static/css/[name].[contenthash:8].css';
52
52
// To have this structure working with relative paths, we have to use custom options.
53
53
const extractTextPluginOptions = shouldUseRelativeAssetPaths
54
54
// Making sure that the publicPath goes back to to build folder.
55
- ? { publicPath : Array ( cssFilename . split ( '/' ) . length ) . join ( '../' ) }
56
- : undefined ;
55
+ ? { publicPath : Array ( cssFilename . split ( '/' ) . length ) . join ( '../' ) }
56
+ : { } ;
57
57
58
58
// This is the production configuration.
59
59
// It compiles slowly and is focused on producing a fast and minimal bundle.
@@ -83,15 +83,15 @@ module.exports = {
83
83
resolve : {
84
84
// This allows you to set a fallback for where Webpack should look for modules.
85
85
// We read `NODE_PATH` environment variable in `paths.js` and pass paths here.
86
- // We use `fallback` instead of `root` because we want `node_modules` to "win"
87
- // if there any conflicts. This matches Node resolution mechanism.
86
+ // We placed these paths second because we want `node_modules` to "win"
87
+ // if there are any conflicts. This matches Node resolution mechanism.
88
88
// https://github.com/facebookincubator/create-react-app/issues/253
89
- fallback : paths . nodePaths ,
89
+ modules : [ 'node_modules' ] . concat ( paths . nodePaths ) ,
90
90
// These are the reasonable defaults supported by the Node ecosystem.
91
91
// We also include JSX as a common component filename extension to support
92
92
// some tools, although we do not recommend using it, see:
93
93
// https://github.com/facebookincubator/create-react-app/issues/290
94
- extensions : [ '.js' , '.json' , '.jsx' , '' ] ,
94
+ extensions : [ '.js' , '.json' , '.jsx' ] ,
95
95
alias : {
96
96
// Support React Native Web
97
97
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
@@ -102,21 +102,34 @@ module.exports = {
102
102
// Resolve loaders (webpack plugins for CSS, images, transpilation) from the
103
103
// directory of `react-scripts` itself rather than the project directory.
104
104
resolveLoader : {
105
- root : paths . ownNodeModules ,
106
- moduleTemplates : [ '*-loader' ]
105
+ modules : [
106
+ paths . ownNodeModules ,
107
+ // Lerna hoists everything, so we need to look in our app directory
108
+ paths . appNodeModules
109
+ ]
107
110
} ,
108
111
// @remove -on-eject-end
109
112
module : {
110
- // First, run the linter.
111
- // It's important to do this before Babel processes the JS .
112
- preLoaders : [
113
+ rules : [
114
+ // First, run the linter .
115
+ // It's important to do this before Babel processes the JS.
113
116
{
114
117
test : / \. ( j s | j s x ) $ / ,
115
- loader : 'eslint' ,
118
+ enforce : 'pre' ,
119
+ use : [ {
120
+ // @remove -on-eject-begin
121
+ // Point ESLint to our predefined config.
122
+ options : {
123
+ // TODO: consider separate config for production,
124
+ // e.g. to enable no-console and no-debugger only in production.
125
+ configFile : path . join ( __dirname , '../.eslintrc' ) ,
126
+ useEslintrc : false
127
+ } ,
128
+ // @remove -on-eject-end
129
+ loader : 'eslint-loader'
130
+ } ] ,
116
131
include : paths . appSrc
117
- }
118
- ] ,
119
- loaders : [
132
+ } ,
120
133
// ** ADDING/UPDATING LOADERS **
121
134
// The "url" loader handles all assets unless explicitly excluded.
122
135
// The `exclude` list *must* be updated with every change to loader extensions.
@@ -133,8 +146,8 @@ module.exports = {
133
146
/ \. j s o n $ / ,
134
147
/ \. s v g $ /
135
148
] ,
136
- loader : 'url' ,
137
- query : {
149
+ loader : 'url-loader ' ,
150
+ options : {
138
151
limit : 10000 ,
139
152
name : 'static/media/[name].[hash:8].[ext]'
140
153
}
@@ -143,9 +156,9 @@ module.exports = {
143
156
{
144
157
test : / \. ( j s | j s x ) $ / ,
145
158
include : paths . appSrc ,
146
- loader : 'babel' ,
159
+ loader : 'babel-loader ' ,
147
160
// @remove -on-eject-begin
148
- query : {
161
+ options : {
149
162
babelrc : false ,
150
163
presets : [ require . resolve ( 'babel-preset-react-app' ) ] ,
151
164
} ,
@@ -165,53 +178,48 @@ module.exports = {
165
178
// in the main CSS file.
166
179
{
167
180
test : / \. c s s $ / ,
168
- loader : ExtractTextPlugin . extract (
169
- 'style' ,
170
- 'css?importLoaders=1!postcss' ,
171
- extractTextPluginOptions
172
- )
181
+ loader : ExtractTextPlugin . extract ( Object . assign ( {
182
+ fallback : 'style-loader' ,
183
+ use : [
184
+ {
185
+ loader : 'css-loader' ,
186
+ options : {
187
+ importLoaders : 1
188
+ }
189
+ } , {
190
+ loader : 'postcss-loader' ,
191
+ options : {
192
+ ident : 'postcss' , // https://webpack.js.org/guides/migrating/#complex-options
193
+ plugins : function ( ) {
194
+ return [
195
+ autoprefixer ( {
196
+ browsers : [
197
+ '>1%' ,
198
+ 'last 4 versions' ,
199
+ 'Firefox ESR' ,
200
+ 'not ie < 9' , // React doesn't support IE8 anyway
201
+ ]
202
+ } )
203
+ ]
204
+ }
205
+ }
206
+ }
207
+ ]
208
+ } , extractTextPluginOptions ) )
173
209
// Note: this won't work without `new ExtractTextPlugin()` in `plugins`.
174
210
} ,
175
- // JSON is not enabled by default in Webpack but both Node and Browserify
176
- // allow it implicitly so we also enable it.
177
- {
178
- test : / \. j s o n $ / ,
179
- loader : 'json'
180
- } ,
181
211
// "file" loader for svg
182
212
{
183
213
test : / \. s v g $ / ,
184
- loader : 'file' ,
185
- query : {
214
+ loader : 'file-loader ' ,
215
+ options : {
186
216
name : 'static/media/[name].[hash:8].[ext]'
187
217
}
188
218
}
189
219
// ** STOP ** Are you adding a new loader?
190
220
// Remember to add the new extension(s) to the "url" loader exclusion list.
191
221
]
192
222
} ,
193
- // @remove -on-eject-begin
194
- // Point ESLint to our predefined config.
195
- eslint : {
196
- // TODO: consider separate config for production,
197
- // e.g. to enable no-console and no-debugger only in production.
198
- configFile : path . join ( __dirname , '../.eslintrc' ) ,
199
- useEslintrc : false
200
- } ,
201
- // @remove -on-eject-end
202
- // We use PostCSS for autoprefixing only.
203
- postcss : function ( ) {
204
- return [
205
- autoprefixer ( {
206
- browsers : [
207
- '>1%' ,
208
- 'last 4 versions' ,
209
- 'Firefox ESR' ,
210
- 'not ie < 9' , // React doesn't support IE8 anyway
211
- ]
212
- } ) ,
213
- ] ;
214
- } ,
215
223
plugins : [
216
224
// Makes some environment variables available in index.html.
217
225
// The public URL is available as %PUBLIC_URL% in index.html, e.g.:
@@ -241,10 +249,6 @@ module.exports = {
241
249
// It is absolutely essential that NODE_ENV was set to production here.
242
250
// Otherwise React will be compiled in the very slow development mode.
243
251
new webpack . DefinePlugin ( env . stringified ) ,
244
- // This helps ensure the builds are consistent if source hasn't changed:
245
- new webpack . optimize . OccurrenceOrderPlugin ( ) ,
246
- // Try to dedupe duplicated modules, if any:
247
- new webpack . optimize . DedupePlugin ( ) ,
248
252
// Minify the code.
249
253
new webpack . optimize . UglifyJsPlugin ( {
250
254
compress : {
@@ -257,10 +261,13 @@ module.exports = {
257
261
output : {
258
262
comments : false ,
259
263
screw_ie8 : true
260
- }
264
+ } ,
265
+ sourceMap : true
261
266
} ) ,
262
267
// Note: this won't work without ExtractTextPlugin.extract(..) in `loaders`.
263
- new ExtractTextPlugin ( cssFilename ) ,
268
+ new ExtractTextPlugin ( {
269
+ filename : cssFilename
270
+ } ) ,
264
271
// Generate a manifest file which contains a mapping of all asset filenames
265
272
// to their corresponding output file so that tools can pick it up without
266
273
// having to parse `index.html`.
0 commit comments