Unverified Commit 91f60cda authored by Joe Haddad's avatar Joe Haddad Committed by GitHub

refactor(webpack): extract splitChunksConfig (#8161)

parent 25fd3f86
...@@ -176,6 +176,56 @@ export default async function getBaseWebpackConfig( ...@@ -176,6 +176,56 @@ export default async function getBaseWebpackConfig(
const devtool = dev ? 'cheap-module-source-map' : false const devtool = dev ? 'cheap-module-source-map' : false
// Contains various versions of the Webpack SplitChunksPlugin used in different build types
const splitChunksConfigs: {
[propName: string]: webpack.Options.SplitChunksOptions
} = {
dev: {
cacheGroups: {
default: false,
vendors: false,
},
},
selective: {
cacheGroups: {
default: false,
vendors: false,
react: {
name: 'commons',
chunks: 'all',
test: /[\\/]node_modules[\\/](react|react-dom)[\\/]/,
},
},
},
prod: {
chunks: 'all',
cacheGroups: {
default: false,
vendors: false,
commons: {
name: 'commons',
chunks: 'all',
minChunks: totalPages > 2 ? totalPages * 0.5 : 2,
},
react: {
name: 'commons',
chunks: 'all',
test: /[\\/]node_modules[\\/](react|react-dom)[\\/]/,
},
},
},
}
// Select appropriate SplitChunksPlugin config for this build
let splitChunksConfig: webpack.Options.SplitChunksOptions
if (dev) {
splitChunksConfig = splitChunksConfigs.dev
} else if (selectivePageBuilding) {
splitChunksConfig = splitChunksConfigs.selective
} else {
splitChunksConfig = splitChunksConfigs.prod
}
const crossOrigin = const crossOrigin =
!config.crossOrigin && config.experimental.modern !config.crossOrigin && config.experimental.modern
? 'anonymous' ? 'anonymous'
...@@ -278,42 +328,7 @@ export default async function getBaseWebpackConfig( ...@@ -278,42 +328,7 @@ export default async function getBaseWebpackConfig(
: { : {
name: CLIENT_STATIC_FILES_RUNTIME_WEBPACK, name: CLIENT_STATIC_FILES_RUNTIME_WEBPACK,
}, },
splitChunks: dev splitChunks: splitChunksConfig,
? {
cacheGroups: {
default: false,
vendors: false,
},
}
: selectivePageBuilding
? {
cacheGroups: {
default: false,
vendors: false,
react: {
name: 'commons',
chunks: 'all',
test: /[\\/]node_modules[\\/](react|react-dom)[\\/]/,
},
},
}
: {
chunks: 'all',
cacheGroups: {
default: false,
vendors: false,
commons: {
name: 'commons',
chunks: 'all',
minChunks: totalPages > 2 ? totalPages * 0.5 : 2,
},
react: {
name: 'commons',
chunks: 'all',
test: /[\\/]node_modules[\\/](react|react-dom)[\\/]/,
},
},
},
minimize: !dev, minimize: !dev,
minimizer: !dev minimizer: !dev
? [ ? [
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment