@@ -4,35 +4,25 @@ 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' ) ;
7+ const MiniCssExtractPlugin = require ( "mini-css-extract -plugin" ) ;
88const ManifestPlugin = require ( 'webpack-manifest-plugin' ) ;
9- const InterpolateHtmlPlugin = require ( 'react-dev-utils/InterpolateHtmlPlugin' ) ;
109const SWPrecacheWebpackPlugin = require ( 'sw-precache-webpack-plugin' ) ;
1110const eslintFormatter = require ( 'react-dev-utils/eslintFormatter' ) ;
1211const ModuleScopePlugin = require ( 'react-dev-utils/ModuleScopePlugin' ) ;
1312const paths = require ( './paths' ) ;
1413const getClientEnvironment = require ( './env' ) ;
1514
1615const publicPath = paths . servedPath ;
17- const shouldUseRelativeAssetPaths = publicPath === './' ;
18- const shouldUseSourceMap = process . env . GENERATE_SOURCEMAP !== 'false' ;
1916const publicUrl = publicPath . slice ( 0 , - 1 ) ;
2017const env = getClientEnvironment ( publicUrl ) ;
2118
2219if ( env . stringified [ 'process.env' ] . NODE_ENV !== '"production"' ) {
2320 throw new Error ( 'Production builds must have NODE_ENV=production.' ) ;
2421}
2522
26- const cssFilename = 'static/css/[name].[contenthash:8].css' ;
27-
28- const extractTextPluginOptions = shouldUseRelativeAssetPaths
29- ?
30- { publicPath : Array ( cssFilename . split ( '/' ) . length ) . join ( '../' ) }
31- : { } ;
32-
3323module . exports = {
24+ mode : 'production' ,
3425 bail : true ,
35- devtool : shouldUseSourceMap ? 'source-map' : false ,
3626 entry : [ require . resolve ( './polyfills' ) , paths . appIndexJs ] ,
3727 output : {
3828 path : paths . appBuild ,
@@ -100,55 +90,43 @@ module.exports = {
10090 } ,
10191 {
10292 test : / \. ( l e s s | c s s ) $ / ,
103- loader : ExtractTextPlugin . extract (
104- Object . assign (
105- {
106- fallback : {
107- loader : require . resolve ( 'style-loader' ) ,
108- options : {
109- hmr : false ,
110- } ,
111- } ,
112- use : [
113- {
114- loader : require . resolve ( 'css-loader' ) ,
115- options : {
116- importLoaders : 1 ,
117- minimize : true ,
118- sourceMap : shouldUseSourceMap ,
119- modules : true ,
120- localIdentName : '[local]--[hash:base64:5]'
121- } ,
122- } ,
123- {
124- loader : require . resolve ( 'postcss-loader' ) ,
125- options : {
126- ident : 'postcss' ,
127- plugins : ( ) => [
128- require ( 'postcss-flexbugs-fixes' ) ,
129- autoprefixer ( {
130- browsers : [
131- '>1%' ,
132- 'last 4 versions' ,
133- 'Firefox ESR' ,
134- 'not ie < 9' , // React doesn't support IE8 anyway
135- ] ,
136- flexbox : 'no-2009' ,
137- } ) ,
138- require ( 'postcss-pxtorem' ) ( {
139- rootValue : 75 ,
140- propList : [ '*' ]
141- } ) ,
142- require ( 'precss' )
143- ] ,
144- } ,
145- } ,
146- require . resolve ( 'less-loader' )
93+ use : [
94+ MiniCssExtractPlugin . loader ,
95+ {
96+ loader : require . resolve ( 'css-loader' ) ,
97+ options : {
98+ importLoaders : 1 ,
99+ minimize : true ,
100+ sourceMap : true ,
101+ modules : true ,
102+ localIdentName : '[local]--[hash:base64:5]'
103+ }
104+ } ,
105+ {
106+ loader : require . resolve ( 'postcss-loader' ) ,
107+ options : {
108+ ident : 'postcss' ,
109+ plugins : ( ) => [
110+ require ( 'postcss-flexbugs-fixes' ) ,
111+ autoprefixer ( {
112+ browsers : [
113+ '>1%' ,
114+ 'last 4 versions' ,
115+ 'Firefox ESR' ,
116+ 'not ie < 9' , // React doesn't support IE8 anyway
117+ ] ,
118+ flexbox : 'no-2009' ,
119+ } ) ,
120+ require ( 'postcss-pxtorem' ) ( {
121+ rootValue : 75 ,
122+ propList : [ '*' ]
123+ } ) ,
124+ require ( 'precss' )
147125 ] ,
148126 } ,
149- extractTextPluginOptions
150- )
151- ) ,
127+ } ,
128+ require . resolve ( 'less-loader' )
129+ ]
152130 } ,
153131 {
154132 loader : require . resolve ( 'file-loader' ) ,
@@ -161,11 +139,33 @@ module.exports = {
161139 } ,
162140 ] ,
163141 } ,
142+ optimization : {
143+ splitChunks : {
144+ chunks : 'all' ,
145+ minSize : 30000 ,
146+ maxSize : 0 ,
147+ minChunks : 1 ,
148+ maxAsyncRequests : 5 ,
149+ maxInitialRequests : 3 ,
150+ automaticNameDelimiter : '~' ,
151+ name : true ,
152+ cacheGroups : {
153+ vendors : {
154+ test : / [ \\ / ] n o d e _ m o d u l e s [ \\ / ] / ,
155+ priority : - 10
156+ } ,
157+ default : {
158+ minChunks : 2 ,
159+ priority : - 20 ,
160+ reuseExistingChunk : true
161+ }
162+ }
163+ }
164+ } ,
164165 plugins : [
165- new InterpolateHtmlPlugin ( env . raw ) ,
166166 new HtmlWebpackPlugin ( {
167167 inject : true ,
168- hash : true ,
168+ hash : true ,
169169 template : paths . appHtml ,
170170 minify : {
171171 removeComments : true ,
@@ -181,22 +181,8 @@ module.exports = {
181181 } ,
182182 } ) ,
183183 new webpack . DefinePlugin ( env . stringified ) ,
184- new webpack . optimize . UglifyJsPlugin ( {
185- compress : {
186- warnings : false ,
187- comparisons : false ,
188- } ,
189- mangle : {
190- safari10 : true ,
191- } ,
192- output : {
193- comments : false ,
194- ascii_only : true ,
195- } ,
196- sourceMap : shouldUseSourceMap ,
197- } ) ,
198- new ExtractTextPlugin ( {
199- filename : cssFilename ,
184+ new MiniCssExtractPlugin ( {
185+ filename : 'static/css/[contenthash].css' ,
200186 } ) ,
201187 new ManifestPlugin ( {
202188 fileName : 'asset-manifest.json' ,
0 commit comments