Skip to content

Commit ea4dc6f

Browse files
andriijasgaearon
authored andcommitted
- [x] Upgrade to webpack 4.8.X (facebook#4077)
- [x] Utilize webpack 4 development and production modes - [x] Upgrade webpack dev server - [x] Webpack 4 compatible release of thread-loader - [x] Webpack 4 compatible release of HtmlWebpackPlugin - [x] Webpack 4 compatible release of SwPrecacheWebpackPlugin - [x] Webpack 4 compatible release of WebpackManifestPlugin - [x] Update README - [x] Update WebpackDevServerUtils - [x] Update InterpolateHtmlPlugin - [x] Update ModuleScopePlugin - [x] Update WatchMissingNodeModulesPlugin - [x] Move UglifyJS options to webpack 4 optimize - [x] Move InterpolateHtmlPlugin to make it tapable on HtmlWebpackPlugin - [x] vendor splitting via splitChunks.splitChunks (https://twitter.com/wSokra/status/969633336732905474) - [x] long term caching via splitChunks.runtimeChunk (https://twitter.com/wSokra/status/969679223278505985) - [x] Make sure process.env.NODE_ENV is proxied correctly to `react-error-overlay` - [x] Implicit webpack.NamedModulesPlugin in dev config as its default in webpack 4 - [x] Disable webpack performance hints as we have our own filesize reporter - [x] Replace ExtractTextPlugin with MiniCssExtractPlugin - [x] Switch to css whole file minification via OptimizeCSSAssetsPlugin rather than per module css minification to gain performance
1 parent aa718b5 commit ea4dc6f

File tree

4 files changed

+157
-173
lines changed

4 files changed

+157
-173
lines changed

config/webpack.config.dev.js

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,6 @@ const publicUrl = '';
3131
// Get environment variables to inject into our app.
3232
const env = getClientEnvironment(publicUrl);
3333

34-
// Options for PostCSS as we reference these options twice
35-
// Adds vendor prefixing based on your specified browser support in
36-
// package.json
37-
const postCSSLoaderOptions = {
38-
// Necessary for external CSS imports to work
39-
// https://github.com/facebook/create-react-app/issues/2677
40-
ident: 'postcss',
41-
plugins: () => [
42-
require('postcss-flexbugs-fixes'),
43-
autoprefixer({
44-
flexbox: 'no-2009',
45-
}),
46-
],
47-
};
48-
4934
// style files regexes
5035
const cssRegex = /\.css$/;
5136
const cssModuleRegex = /\.module\.css$/;
@@ -61,8 +46,21 @@ const getStyleLoaders = (cssOptions, preProcessor) => {
6146
options: cssOptions,
6247
},
6348
{
49+
// Options for PostCSS as we reference these options twice
50+
// Adds vendor prefixing based on your specified browser support in
51+
// package.json
6452
loader: require.resolve('postcss-loader'),
65-
options: postCSSLoaderOptions,
53+
options: {
54+
// Necessary for external CSS imports to work
55+
// https://github.com/facebook/create-react-app/issues/2677
56+
ident: 'postcss',
57+
plugins: () => [
58+
require('postcss-flexbugs-fixes'),
59+
autoprefixer({
60+
flexbox: 'no-2009',
61+
}),
62+
],
63+
},
6664
},
6765
];
6866
if (preProcessor) {
@@ -75,6 +73,7 @@ const getStyleLoaders = (cssOptions, preProcessor) => {
7573
// It is focused on developer experience and fast rebuilds.
7674
// The production configuration is different and lives in a separate file.
7775
module.exports = {
76+
mode: 'development',
7877
// You may want 'eval' instead if you prefer to see the compiled output in DevTools.
7978
// See the discussion in https://github.com/facebook/create-react-app/issues/343.
8079
devtool: 'cheap-module-source-map',
@@ -116,6 +115,18 @@ module.exports = {
116115
devtoolModuleFilenameTemplate: info =>
117116
path.resolve(info.absoluteResourcePath).replace(/\\/g, '/'),
118117
},
118+
optimization: {
119+
// Automatically split vendor and commons
120+
// https://twitter.com/wSokra/status/969633336732905474
121+
// https://medium.com/webpack/webpack-4-code-splitting-chunk-graph-and-the-splitchunks-optimization-be739a861366
122+
splitChunks: {
123+
chunks: 'all',
124+
name: 'vendors',
125+
},
126+
// Keep the runtime chunk seperated to enable long term caching
127+
// https://twitter.com/wSokra/status/969679223278505985
128+
runtimeChunk: true,
129+
},
119130
resolve: {
120131
// This allows you to set a fallback for where Webpack should look for modules.
121132
// We placed these paths second because we want `node_modules` to "win"
@@ -335,18 +346,16 @@ module.exports = {
335346
],
336347
},
337348
plugins: [
338-
// Makes some environment variables available in index.html.
339-
// The public URL is available as %PUBLIC_URL% in index.html, e.g.:
340-
// <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
341-
// In development, this will be an empty string.
342-
new InterpolateHtmlPlugin(env.raw),
343349
// Generates an `index.html` file with the <script> injected.
344350
new HtmlWebpackPlugin({
345351
inject: true,
346352
template: paths.appHtml,
347353
}),
348-
// Add module names to factory functions so they appear in browser profiler.
349-
new webpack.NamedModulesPlugin(),
354+
// Makes some environment variables available in index.html.
355+
// The public URL is available as %PUBLIC_URL% in index.html, e.g.:
356+
// <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
357+
// In development, this will be an empty string.
358+
new InterpolateHtmlPlugin(env.raw),
350359
// Makes some environment variables available to the JS code, for example:
351360
// if (process.env.NODE_ENV === 'development') { ... }. See `./env.js`.
352361
new webpack.DefinePlugin(env.stringified),
@@ -368,6 +377,7 @@ module.exports = {
368377
// You can remove this if you don't use Moment.js:
369378
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
370379
],
380+
371381
// Some libraries import Node modules but don't use them in the browser.
372382
// Tell Webpack to provide empty mocks for them so importing them works.
373383
node: {
@@ -377,10 +387,7 @@ module.exports = {
377387
tls: 'empty',
378388
child_process: 'empty',
379389
},
380-
// Turn off performance hints during development because we don't do any
381-
// splitting or minification in interest of speed. These warnings become
382-
// cumbersome.
383-
performance: {
384-
hints: false,
385-
},
390+
// Turn off performance processing because we utilize
391+
// our own hints via the FileSizeReporter
392+
performance: false,
386393
};

0 commit comments

Comments
 (0)