Skip to content
This repository has been archived by the owner on May 15, 2023. It is now read-only.

Commit

Permalink
Extract the vendor and the runtime code
Browse files Browse the repository at this point in the history
  • Loading branch information
iamakulov committed Mar 19, 2018
1 parent 4cd532b commit 3733078
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions webpack.config.js
Expand Up @@ -20,10 +20,12 @@ const isProduction = process.env.NODE_ENV === 'production';

module.exports = {
mode: isProduction ? 'production' : 'development',
entry: './src/index.js',
entry: {
main: './src/index.js',
},
output: {
path: path.resolve(__dirname, 'public', 'build'),
filename: isProduction ? 'bundle.[chunkhash].js' : 'bundle.js',
filename: isProduction ? '[name].[chunkhash].js' : '[name].js',
publicPath: '/build/',
},
module: {
Expand Down Expand Up @@ -55,6 +57,12 @@ module.exports = {
},
],
},
optimization: {
splitChunks: {
chunks: 'all',
},
runtimeChunk: true,
},
plugins: [
// Emit HTML files that serve the app
new HtmlWebpackPlugin({
Expand Down

1 comment on commit 3733078

@iamakulov
Copy link
Contributor Author

@iamakulov iamakulov commented on 3733078 Mar 19, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit splits a single bundle into app code, dependencies code, and webpack runtime. Corresponding article section

This allows us to cache them with a higher efficiency – if a developer changes the app code, the user won’t have to re-download dependencies.

Generated files
Before:

                         Asset      Size  Chunks             Chunk Names
bundle.92edb179ea115411a1b2.js   152 KiB       0  [emitted]  main
                 ..\index.html  1.29 KiB          [emitted]
           ..\users\index.html  1.02 KiB          [emitted]

After:

                               Asset      Size  Chunks             Chunk Names
runtime~main.2a2e13c679f6f2471b8a.js  1.05 KiB       0  [emitted]  runtime~main
vendors~main.f7296c4f27876024a9ae.js   139 KiB       1  [emitted]  vendors~main
        main.450f9158b3f1fcb6552a.js  12.3 KiB       2  [emitted]  main
                       ..\index.html  1.47 KiB          [emitted]
                 ..\users\index.html   1.2 KiB          [emitted]

Please sign in to comment.