如何分割@ vue / cli 3个“页面”供应商文件

问题描述 投票:4回答:1

我遵循Vue Cli文档中的此主题Build the app in multi-page mode,它工作正常,但我意识到只有1个供应商文件,而不是2个(每页条目)。

我如何分割供应商文件?我不想在多个页面条目之间共享一个不必要的大供应商文件。 (我想在单个应用程序中使用它。)>

enter image description here

enter image description here

对于上面的屏幕截图,我想为index.xxx.js有一个供应商文件,为report.xxx.js有一个供应商文件

请提出建议,谢谢

我遵循此主题,在Vue Cli doc中以多页模式构建应用程序,它工作正常,但我意识到只有1个供应商文件,而不是2个(每页输入)。如何分割供应商文件?我不...

vue.js vue-cli
1个回答
0
投票
module.exports = {
  pages: {
    index: {
      entry: 'src/monitor/main.js',
      template: 'public/index.html',
      chunks: ['chunk-common', 'chunk-{pagename}-vendors', '{pagename}']
    },
    report: {
      entry: 'src/report/main.js',
      chunks: ['chunk-common', 'chunk-{pagename}-vendors', '{pagename}']
    }
  },

  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: {
          ...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,
          },
        },
      })
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.