mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-12 03:38:07 +00:00
fix: add all node_modules requests into vendor chunk
This commit is contained in:
parent
9e0aa84416
commit
d32419eb92
@ -184,36 +184,18 @@ module.exports = function webpackClientConfig() {
|
|||||||
// Adds Common Chunks Plugin
|
// Adds Common Chunks Plugin
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
function commonChunksPlugin(config) {
|
function commonChunksPlugin(config) {
|
||||||
const _this = this
|
|
||||||
const totalPages = _this.routes ? _this.routes.length : 0
|
|
||||||
|
|
||||||
// This well-known vendor may exist as a dependency of other requests.
|
|
||||||
const maybeVendor = [
|
|
||||||
'/core-js/',
|
|
||||||
'/regenerator-runtime/',
|
|
||||||
'/es6-promise/',
|
|
||||||
'/babel-runtime/',
|
|
||||||
'/lodash/'
|
|
||||||
]
|
|
||||||
|
|
||||||
// Create explicit vendor chunk
|
// Create explicit vendor chunk
|
||||||
config.plugins.unshift(
|
config.plugins.unshift(
|
||||||
new webpack.optimize.CommonsChunkPlugin({
|
new webpack.optimize.CommonsChunkPlugin({
|
||||||
name: 'vendor',
|
name: 'vendor',
|
||||||
filename: this.getFileName('vendor'),
|
filename: this.getFileName('vendor'),
|
||||||
minChunks(module, count) {
|
minChunks(module, count) {
|
||||||
// Detect and externalize well-known vendor if detected
|
|
||||||
if (module.context && maybeVendor.some(v => module.context.includes(v))) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
// A module is extracted into the vendor chunk when...
|
// A module is extracted into the vendor chunk when...
|
||||||
return (
|
return (
|
||||||
// If it's inside node_modules
|
// If it's inside node_modules
|
||||||
/node_modules/.test(module.context) &&
|
/node_modules/.test(module.context) &&
|
||||||
// Do not externalize if the request is a CSS file
|
// Do not externalize if the request is a CSS file
|
||||||
!/\.(css|less|scss|sass|styl|stylus)$/.test(module.request) &&
|
!/\.(css|less|scss|sass|styl|stylus)$/.test(module.request)
|
||||||
// Used in at-least 1/2 of the total pages
|
|
||||||
(totalPages <= 2 ? count >= totalPages : count >= totalPages * 0.5)
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user