【问题标题】:How to split @vue/cli 3 "pages" vendor file如何拆分@vue/cli 3“页面”供应商文件
【发布时间】:2018-12-16 22:43:45
【问题描述】:

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

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

对于上面的截图,我想要一个用于 index.xxx.js 的供应商文件和一个用于 report.xxx.js 的供应商文件

请指教,谢谢

【问题讨论】:

    标签: vue.js vue-cli


    【解决方案1】:
    module.exports = {
      pages: {
        index: {
          entry: 'src/monitor/main.js',
          template: 'public/index.html',
          chunks: ['chunk-common', 'chunk-index-vendors', 'index']
        },
        report: {
          entry: 'src/report/main.js',
          chunks: ['chunk-common', 'chunk-report-vendors', 'report']
        }
      },
    
      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,
              },
            },
          })
      }
    }
    

    它基于 GitHub 线程:https://github.com/vuejs/vue-cli/issues/2381#issuecomment-425038367

    【讨论】:

      猜你喜欢
      • 2019-03-07
      • 2019-08-19
      • 2019-05-26
      • 2020-02-10
      • 2023-03-21
      • 2022-07-10
      • 2021-01-28
      • 2015-09-30
      • 2018-12-30
      相关资源
      最近更新 更多