@@ -52,8 +52,8 @@ const cssFilename = 'static/css/[name].[contenthash:8].css';
5252// To have this structure working with relative paths, we have to use custom options.
5353const extractTextPluginOptions = shouldUseRelativeAssetPaths
5454 // 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+ : { } ;
5757
5858// This is the production configuration.
5959// It compiles slowly and is focused on producing a fast and minimal bundle.
@@ -83,15 +83,15 @@ module.exports = {
8383 resolve : {
8484 // This allows you to set a fallback for where Webpack should look for modules.
8585 // 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.
8888 // https://github.com/facebookincubator/create-react-app/issues/253
89- fallback : paths . nodePaths ,
89+ modules : [ 'node_modules' ] . concat ( paths . nodePaths ) ,
9090 // These are the reasonable defaults supported by the Node ecosystem.
9191 // We also include JSX as a common component filename extension to support
9292 // some tools, although we do not recommend using it, see:
9393 // https://github.com/facebookincubator/create-react-app/issues/290
94- extensions : [ '.js' , '.json' , '.jsx' , '' ] ,
94+ extensions : [ '.js' , '.json' , '.jsx' ] ,
9595 alias : {
9696 // Support React Native Web
9797 // https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
@@ -102,21 +102,34 @@ module.exports = {
102102 // Resolve loaders (webpack plugins for CSS, images, transpilation) from the
103103 // directory of `react-scripts` itself rather than the project directory.
104104 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+ ]
107110 } ,
108111 // @remove -on-eject-end
109112 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.
113116 {
114117 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+ } ] ,
116131 include : paths . appSrc
117- }
118- ] ,
119- loaders : [
132+ } ,
120133 // ** ADDING/UPDATING LOADERS **
121134 // The "url" loader handles all assets unless explicitly excluded.
122135 // The `exclude` list *must* be updated with every change to loader extensions.
@@ -133,8 +146,8 @@ module.exports = {
133146 / \. j s o n $ / ,
134147 / \. s v g $ /
135148 ] ,
136- loader : 'url' ,
137- query : {
149+ loader : 'url-loader ' ,
150+ options : {
138151 limit : 10000 ,
139152 name : 'static/media/[name].[hash:8].[ext]'
140153 }
@@ -143,9 +156,9 @@ module.exports = {
143156 {
144157 test : / \. ( j s | j s x ) $ / ,
145158 include : paths . appSrc ,
146- loader : 'babel' ,
159+ loader : 'babel-loader ' ,
147160 // @remove -on-eject-begin
148- query : {
161+ options : {
149162 babelrc : false ,
150163 presets : [ require . resolve ( 'babel-preset-react-app' ) ] ,
151164 } ,
@@ -165,53 +178,48 @@ module.exports = {
165178 // in the main CSS file.
166179 {
167180 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 ) )
173209 // Note: this won't work without `new ExtractTextPlugin()` in `plugins`.
174210 } ,
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- } ,
181211 // "file" loader for svg
182212 {
183213 test : / \. s v g $ / ,
184- loader : 'file' ,
185- query : {
214+ loader : 'file-loader ' ,
215+ options : {
186216 name : 'static/media/[name].[hash:8].[ext]'
187217 }
188218 }
189219 // ** STOP ** Are you adding a new loader?
190220 // Remember to add the new extension(s) to the "url" loader exclusion list.
191221 ]
192222 } ,
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- } ,
215223 plugins : [
216224 // Makes some environment variables available in index.html.
217225 // The public URL is available as %PUBLIC_URL% in index.html, e.g.:
@@ -241,10 +249,6 @@ module.exports = {
241249 // It is absolutely essential that NODE_ENV was set to production here.
242250 // Otherwise React will be compiled in the very slow development mode.
243251 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 ( ) ,
248252 // Minify the code.
249253 new webpack . optimize . UglifyJsPlugin ( {
250254 compress : {
@@ -257,10 +261,13 @@ module.exports = {
257261 output : {
258262 comments : false ,
259263 screw_ie8 : true
260- }
264+ } ,
265+ sourceMap : true
261266 } ) ,
262267 // Note: this won't work without ExtractTextPlugin.extract(..) in `loaders`.
263- new ExtractTextPlugin ( cssFilename ) ,
268+ new ExtractTextPlugin ( {
269+ filename : cssFilename
270+ } ) ,
264271 // Generate a manifest file which contains a mapping of all asset filenames
265272 // to their corresponding output file so that tools can pick it up without
266273 // having to parse `index.html`.
0 commit comments