move to vendor chunk if only in at-least 1/2 of the total pages or dev

~> next.js
This commit is contained in:
Pooya Parsa 2017-06-07 23:07:12 +04:30
parent ad9ec1470d
commit 6fa25cacc2
3 changed files with 11 additions and 13 deletions

View File

@ -186,14 +186,7 @@ async function generateRoutesAndFiles () {
options: this.options,
uniqBy: _.uniqBy,
isDev: this.dev,
router: {
mode: this.options.router.mode,
base: this.options.router.base,
middleware: this.options.router.middleware,
linkActiveClass: this.options.router.linkActiveClass,
linkExactActiveClass: this.options.router.linkExactActiveClass,
scrollBehavior: this.options.router.scrollBehavior
},
router: this.options.router,
env: this.options.env,
head: this.options.head,
middleware: fs.existsSync(join(this.srcDir, 'middleware')),

View File

@ -48,7 +48,8 @@ class Nuxt {
linkActiveClass: 'nuxt-link-active',
linkExactActiveClass: 'nuxt-link-exact-active',
extendRoutes: null,
scrollBehavior: null
scrollBehavior: null,
routes: []
},
render: {
http2: {
@ -73,7 +74,7 @@ class Nuxt {
if (options.router && typeof options.router.base === 'string') {
this._routerBaseSpecified = true
}
if (typeof options.transition === 'string') options.transition = {name: options.transition}
if (typeof options.transition === 'string') options.transition = { name: options.transition }
this.options = _.defaultsDeep(options, defaults)
// Ready variable
this._ready = false

View File

@ -43,6 +43,7 @@ export default function () {
env['process.env.' + key] = (typeof value === 'string' ? JSON.stringify(value) : value)
})
// Webpack plugins
const self = this
config.plugins = (config.plugins || []).concat([
// Strip comments in Vue code
new webpack.DefinePlugin(Object.assign(env, {
@ -56,13 +57,16 @@ export default function () {
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
filename: this.options.build.filenames.vendor,
minChunks (module) {
minChunks (module, count) {
const totalPages = (self.options.router.routes && self.options.router.routes.length) || 0
// A module is extracted into the vendor chunk when...
return (
// 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
!/\.(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 or dev mode
(self.options.dev || (count >= totalPages * 0.5))
)
}
}),