fix problems with common chunk

This commit is contained in:
Pooya Parsa 2017-08-21 23:42:41 +04:30
parent e19939c10a
commit 7973d67f5b
2 changed files with 13 additions and 9 deletions

View File

@ -72,11 +72,7 @@ export default class Builder extends Tapable {
'vue',
'vue-router',
'vue-meta',
'core-js',
'regenerator-runtime',
'es6-promise',
'babel-runtime',
'vuex'
this.options.store && 'vuex'
].concat(this.options.build.vendor).filter(v => v)
}

View File

@ -29,11 +29,20 @@ export default function webpackClientConfig () {
// App entry
config.entry.app = resolve(this.options.buildDir, 'client.js')
config.entry.common = this.vendor()
// Extract vendor chunks for better caching
const _this = this
const totalPages = _this.routes ? _this.routes.length : 0
const vendor = this.vendor()
// This well-known vendor may exist as a dependency of other requests.
const maybeVendor = [
'/core-js/',
'/regenerator-runtime/',
'/es6-promise/',
'/babel-runtime/',
'/lodash/'
]
config.plugins.push(
new webpack.optimize.CommonsChunkPlugin({
@ -47,9 +56,8 @@ export default function webpackClientConfig () {
return false
}
// Extract all explicit vendor modules
// Vendor should explicitly extracted even if not used in 50% of the chunks!
if (module.context && vendor.some(v => module.context.includes(v))) {
// Detect and externalize well-known vendor if detected
if (module.context && maybeVendor.some(v => module.context.includes(v))) {
return true
}