Skip to content

Commit

Permalink
Merge pull request #13235 from kidroca/kidroca/chore/webpack-bundle-s…
Browse files Browse the repository at this point in the history
…plitting
  • Loading branch information
roryabraham authored Dec 6, 2022
2 parents 2f06cae + 35b1d98 commit b9753e5
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions config/webpack/webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,26 @@ const webpackConfig = ({envFile = '.env', platform = 'web'}) => ({
'process/browser': require.resolve('process/browser'),
},
},
optimization: {
runtimeChunk: 'single',
splitChunks: {
cacheGroups: {
// Extract all 3rd party dependencies (~75% of App) to separate js file
// This gives a more efficient caching - 3rd party deps don't change as often as main source
// When dependencies don't change webpack would produce the same js file (and content hash)
// After App update end users would download just the main source and resolve the rest from cache
// When dependencies do change cache is invalidated and users download everything - same as before
vendor: {
test: /[\\/]node_modules[\\/]/,
name: 'vendors',

// Capture only the scripts needed for the initial load, so any async imports
// would be grouped (and lazy loaded) separately
chunks: 'initial',
},
},
},
},
});

module.exports = webpackConfig;

0 comments on commit b9753e5

Please sign in to comment.