Skip to content

Commit

Permalink
fix problems with common chunk
Browse files Browse the repository at this point in the history
  • Loading branch information
Pooya Parsa committed Aug 21, 2017
1 parent e19939c commit 7973d67
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
6 changes: 1 addition & 5 deletions lib/builder/builder.js
Expand Up @@ -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)
}

Expand Down
16 changes: 12 additions & 4 deletions lib/builder/webpack/client.config.js
Expand Up @@ -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({
Expand All @@ -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
}

Expand Down

0 comments on commit 7973d67

Please sign in to comment.