Skip to content

Instantly share code, notes, and snippets.

@Akryum
Created September 27, 2018 10:18
Show Gist options
  • Save Akryum/ece2ca512a1f40d70a1d467566783219 to your computer and use it in GitHub Desktop.
Save Akryum/ece2ca512a1f40d70a1d467566783219 to your computer and use it in GitHub Desktop.

Revisions

  1. Akryum created this gist Sep 27, 2018.
    46 changes: 46 additions & 0 deletions vue.config.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@
    module.exports = {
    pages: {
    pageA: 'src/pageA.js',
    pageB: 'src/pageB.js',
    pageC: 'src/pageC.js',
    },

    chainWebpack: config => {
    const options = module.exports
    const pages = options.pages
    const pageKeys = Object.keys(pages)

    // Long-term caching

    const IS_VENDOR = /[\\/]node_modules[\\/]/

    config.optimization
    .splitChunks({
    cacheGroups: {
    vendors: {
    name: 'chunk-vendors',
    priority: -10,
    chunks: 'initial',
    minChunks: 2,
    test: IS_VENDOR,
    enforce: true,
    },
    ...pageKeys.map(key => ({
    name: `chunk-${key}-vendors`,
    priority: -11,
    chunks: chunk => chunk.name === key,
    test: IS_VENDOR,
    enforce: true,
    })),
    common: {
    name: 'chunk-common',
    priority: -20,
    chunks: 'initial',
    minChunks: 2,
    reuseExistingChunk: true,
    enforce: true,
    },
    },
    })
    }
    }