mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +00:00
better common chunks
This commit is contained in:
parent
9bfd00d3f4
commit
f42783af32
@ -18,7 +18,7 @@ export default function webpackBaseConfig ({ isClient, isServer }) {
|
||||
const config = {
|
||||
devtool: this.options.dev ? 'cheap-module-source-map' : 'nosources-source-map',
|
||||
entry: {
|
||||
vendor: ['vue', 'vue-router', 'vue-meta']
|
||||
app: null
|
||||
},
|
||||
output: {
|
||||
path: resolve(this.options.buildDir, 'dist'),
|
||||
|
@ -24,20 +24,28 @@ export default function webpackClientConfig () {
|
||||
|
||||
config.name = 'client'
|
||||
|
||||
// Entry
|
||||
// App entry
|
||||
config.entry.app = resolve(this.options.buildDir, 'client.js')
|
||||
|
||||
// Add vendors
|
||||
if (this.options.store) {
|
||||
config.entry.vendor.push('vuex')
|
||||
}
|
||||
config.entry.vendor = config.entry.vendor.concat(this.options.build.vendor)
|
||||
// This vendors should explicitly extracted
|
||||
// Even if not used in 50% of the chunks!
|
||||
const vendor = [
|
||||
'vue',
|
||||
'vue-router',
|
||||
'vue-meta',
|
||||
'core-js',
|
||||
'regenerator-runtime',
|
||||
'es6-promise',
|
||||
'babel-runtime',
|
||||
this.options.store && 'vuex'
|
||||
].concat(this.options.build.vendor).filter(v => v)
|
||||
|
||||
// Extract vendor chunks for better caching
|
||||
const _this = this
|
||||
config.plugins.push(
|
||||
new webpack.optimize.CommonsChunkPlugin({
|
||||
name: 'vendor',
|
||||
name: 'common',
|
||||
filename: this.options.build.filenames.vendor,
|
||||
minChunks (module, count) {
|
||||
// In the dev we use on-demand-entries.
|
||||
@ -47,6 +55,11 @@ export default function webpackClientConfig () {
|
||||
return false
|
||||
}
|
||||
|
||||
// Extract all explicit vendor modules
|
||||
if (module.context && vendor.some(v => module.context.includes(v))) {
|
||||
return true
|
||||
}
|
||||
|
||||
// Total pages
|
||||
const totalPages = _this.routes ? _this.routes.length : 0
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user