@@ -4,10 +4,7 @@ const autoprefixer = require('autoprefixer');
44const path = require ( 'path' ) ;
55const webpack = require ( 'webpack' ) ;
66const HtmlWebpackPlugin = require ( 'html-webpack-plugin' ) ;
7- const ExtractTextPlugin = require ( 'extract-text-webpack-plugin' ) ;
8- const ManifestPlugin = require ( 'webpack-manifest-plugin' ) ;
97const InterpolateHtmlPlugin = require ( 'react-dev-utils/InterpolateHtmlPlugin' ) ;
10- const SWPrecacheWebpackPlugin = require ( 'sw-precache-webpack-plugin' ) ;
118const ModuleScopePlugin = require ( 'react-dev-utils/ModuleScopePlugin' ) ;
129const ForkTsCheckerWebpackPlugin = require ( 'fork-ts-checker-webpack-plugin' ) ;
1310const paths = require ( './paths' ) ;
@@ -36,18 +33,6 @@ if (env.stringified['process.env'].NODE_ENV !== '"production"') {
3633 throw new Error ( 'Production builds must have NODE_ENV=production.' ) ;
3734}
3835
39- // Note: defined here because it will be used more than once.
40- const cssFilename = 'static/css/[name].[contenthash:8].css' ;
41-
42- // ExtractTextPlugin expects the build output to be flat.
43- // (See https://github.com/webpack-contrib/extract-text-webpack-plugin/issues/27)
44- // However, our output is structured with css, js and media folders.
45- // To have this structure working with relative paths, we have to use custom options.
46- const extractTextPluginOptions = shouldUseRelativeAssetPaths
47- ? // Making sure that the publicPath goes back to to build folder.
48- { publicPath : Array ( cssFilename . split ( '/' ) . length ) . join ( '../' ) }
49- : { } ;
50-
5136// This is the production configuration.
5237// It compiles slowly and is focused on producing a fast and minimal bundle.
5338// The development configuration is different and lives in a separate file.
@@ -94,6 +79,13 @@ module.exports = {
9479 // https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
9580 'react-native' : 'react-native-web' ,
9681 } ,
82+ fallback : {
83+ dgram : false ,
84+ fs : false ,
85+ net : false ,
86+ tls : false ,
87+ child_process : false ,
88+ } ,
9789 plugins : [
9890 // Prevents users from importing files from outside of src/ (or node_modules/).
9991 // This often causes confusion because we only process files within src/ with babel.
@@ -156,7 +148,7 @@ module.exports = {
156148 } ,
157149 {
158150 test : / \. m o d u l e \. s ( a | c ) s s $ / ,
159- loader : [
151+ use : [
160152 require . resolve ( 'style-loader' ) ,
161153 // isDevelopment ? 'style-loader' : MiniCssExtractPlugin.loader,
162154 {
@@ -182,64 +174,46 @@ module.exports = {
182174 'sass-loader' , // compiles Sass to CSS, using Node Sass by default
183175 ] ,
184176 } ,
185- // The notation here is somewhat confusing.
186177 // "postcss" loader applies autoprefixer to our CSS.
187178 // "css" loader resolves paths in CSS and adds assets as dependencies.
188- // "style" loader normally turns CSS into JS modules injecting <style>,
189- // but unlike in development configuration, we do something different.
190- // `ExtractTextPlugin` first applies the "postcss" and "css" loaders
191- // (second argument), then grabs the result CSS and puts it into a
192- // separate file in our build process. This way we actually ship
193- // a single CSS file in production instead of JS code injecting <style>
194- // tags. If you use code splitting, however, any async bundles will still
195- // use the "style" loader inside the async code so CSS from them won't be
196- // in the main CSS file.
179+ // "style" loader turns CSS into JS modules that inject <style> tags.
197180 {
198181 test : / \. c s s $ / ,
199- loader : ExtractTextPlugin . extract (
200- Object . assign (
201- {
202- fallback : {
203- loader : require . resolve ( 'style-loader' ) ,
204- options : {
205- hmr : false ,
206- } ,
207- } ,
208- use : [
209- {
210- loader : require . resolve ( 'css-loader' ) ,
211- options : {
212- importLoaders : 1 ,
213- minimize : true ,
214- sourceMap : shouldUseSourceMap ,
215- } ,
216- } ,
217- {
218- loader : require . resolve ( 'postcss-loader' ) ,
219- options : {
220- // Necessary for external CSS imports to work
221- // https://github.com/facebookincubator/create-react-app/issues/2677
222- ident : 'postcss' ,
223- plugins : ( ) => [
224- require ( 'postcss-flexbugs-fixes' ) ,
225- autoprefixer ( {
226- browsers : [
227- '>1%' ,
228- 'last 4 versions' ,
229- 'Firefox ESR' ,
230- 'not ie < 9' , // React doesn't support IE8 anyway
231- ] ,
232- flexbox : 'no-2009' ,
233- } ) ,
234- ] ,
235- } ,
236- } ,
182+ use : [
183+ {
184+ loader : require . resolve ( 'style-loader' ) ,
185+ options : {
186+ hmr : false ,
187+ } ,
188+ } ,
189+ {
190+ loader : require . resolve ( 'css-loader' ) ,
191+ options : {
192+ importLoaders : 1 ,
193+ sourceMap : shouldUseSourceMap ,
194+ } ,
195+ } ,
196+ {
197+ loader : require . resolve ( 'postcss-loader' ) ,
198+ options : {
199+ // Necessary for external CSS imports to work
200+ // https://github.com/facebookincubator/create-react-app/issues/2677
201+ ident : 'postcss' ,
202+ plugins : ( ) => [
203+ require ( 'postcss-flexbugs-fixes' ) ,
204+ autoprefixer ( {
205+ browsers : [
206+ '>1%' ,
207+ 'last 4 versions' ,
208+ 'Firefox ESR' ,
209+ 'not ie < 9' , // React doesn't support IE8 anyway
210+ ] ,
211+ flexbox : 'no-2009' ,
212+ } ) ,
237213 ] ,
238214 } ,
239- extractTextPluginOptions
240- )
241- ) ,
242- // Note: this won't work without `new ExtractTextPlugin()` in `plugins`.
215+ } ,
216+ ] ,
243217 } ,
244218
245219 // "file" loader makes sure assets end up in the `build` folder.
@@ -328,69 +302,21 @@ module.exports = {
328302 // Use multi-process parallel running to improve the build speed
329303 // Default number of concurrent runs: os.cpus().length - 1
330304 parallel : true ,
331- // Enable file caching
332- cache : true ,
333- sourceMap : shouldUseSourceMap ,
334- } ) , // Note: this won't work without ExtractTextPlugin.extract(..) in `loaders`.
335- new ExtractTextPlugin ( {
336- filename : cssFilename ,
337- } ) ,
338- // Generate a manifest file which contains a mapping of all asset filenames
339- // to their corresponding output file so that tools can pick it up without
340- // having to parse `index.html`.
341- new ManifestPlugin ( {
342- fileName : 'asset-manifest.json' ,
343- } ) ,
344- // Generate a service worker script that will precache, and keep up to date,
345- // the HTML & assets that are part of the Webpack build.
346- new SWPrecacheWebpackPlugin ( {
347- // By default, a cache-busting query parameter is appended to requests
348- // used to populate the caches, to ensure the responses are fresh.
349- // If a URL is already hashed by Webpack, then there is no concern
350- // about it being stale, and the cache-busting can be skipped.
351- dontCacheBustUrlsMatching : / \. \w { 8 } \. / ,
352- filename : 'service-worker.js' ,
353- logger ( message ) {
354- if ( message . indexOf ( 'Total precache size is' ) === 0 ) {
355- // This message occurs for every build and is a bit too noisy.
356- return ;
357- }
358- if ( message . indexOf ( 'Skipping static resource' ) === 0 ) {
359- // This message obscures real errors so we ignore it.
360- // https://github.com/facebookincubator/create-react-app/issues/2612
361- return ;
362- }
363- console . log ( message ) ;
364- } ,
365- minify : true ,
366- // For unknown URLs, fallback to the index page
367- navigateFallback : publicUrl + '/index.html' ,
368- // Ignores URLs starting from /__ (useful for Firebase):
369- // https://github.com/facebookincubator/create-react-app/issues/2237#issuecomment-302693219
370- navigateFallbackWhitelist : [ / ^ (? ! \/ _ _ ) .* / ] ,
371- // Don't precache sourcemaps (they're large) and build asset manifest:
372- staticFileGlobsIgnorePatterns : [ / \. m a p $ / , / a s s e t - m a n i f e s t \. j s o n $ / ] ,
373305 } ) ,
374306 // Moment.js is an extremely popular library that bundles large locale files
375307 // by default due to how Webpack interprets its code. This is a practical
376308 // solution that requires the user to opt into importing specific locales.
377309 // https://github.com/jmblog/how-to-optimize-momentjs-with-webpack
378310 // You can remove this if you don't use Moment.js:
379- new webpack . IgnorePlugin ( / ^ \. \/ l o c a l e $ / , / m o m e n t $ / ) ,
311+ new webpack . IgnorePlugin ( {
312+ resourceRegExp : / ^ \. \/ l o c a l e $ / ,
313+ contextRegExp : / m o m e n t $ / ,
314+ } ) ,
380315 // Perform type checking and linting in a separate process to speed up compilation
381316 new ForkTsCheckerWebpackPlugin ( {
382317 async : false ,
383318 tsconfig : paths . appTsProdConfig ,
384319 tslint : paths . appTsLint ,
385320 } ) ,
386321 ] ,
387- // Some libraries import Node modules but don't use them in the browser.
388- // Tell Webpack to provide empty mocks for them so importing them works.
389- node : {
390- dgram : 'empty' ,
391- fs : 'empty' ,
392- net : 'empty' ,
393- tls : 'empty' ,
394- child_process : 'empty' ,
395- } ,
396322} ;
0 commit comments