mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-07 09:22:27 +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
|
||||
// --------------------------------------------------------------------------
|
||||
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
|
||||
config.plugins.unshift(
|
||||
new webpack.optimize.CommonsChunkPlugin({
|
||||
name: 'vendor',
|
||||
filename: this.getFileName('vendor'),
|
||||
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...
|
||||
return (
|
||||
// If it's inside node_modules
|
||||
/node_modules/.test(module.context) &&
|
||||
// Do not externalize if the request is a CSS file
|
||||
!/\.(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)
|
||||
!/\.(css|less|scss|sass|styl|stylus)$/.test(module.request)
|
||||
)
|
||||
}
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user