首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >webpack 5升级后如何从CommonsChunkPlugin迁移到splitChunks

webpack 5升级后如何从CommonsChunkPlugin迁移到splitChunks
EN

Stack Overflow用户
提问于 2022-01-15 15:05:49
回答 1查看 165关注 0票数 0

我正在开发一个google chrome扩展程序,当我使用较低版本的webpack时,我用这样的方式来配置代码块:

代码语言:javascript
复制
    plugins : [
    new CommonsChunkPlugin( {
      name : 'commons1',
      filename : 'commons1.js' , 
      allChunks: true,
      chunks : [ 'popup','content' ],
      chunksSortMode: 'manual',
    }) ,
    new CommonsChunkPlugin({ 
      name: 'commons2',
      filename :'commons2.js' , 
      allChunks: true,
      chunks : [ 'commons1.js' , 'options' ] 
    }) ,
    new CommonsChunkPlugin({ 
      name: 'commons3',
      filename :'commons3.js' , 
      allChunks: true,
      chunks : [ 'bg' , 'commons2.js' ] 
    }) ,
    new ExtractTextPlugin( '[name].css' )
  ]

在完成webpack 5旅之后,他们删除了CommonsChunkPlugin并使用了splitChunks,我读了splitChunks文档,不知道如何将我的旧配置迁移到新的splitChunks。是否可以将旧配置迁移到新的splitChunks?使用splitChunks编写连续化的平等方式是什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-01-17 04:13:50

在splitChunk中,我是这样写的:

代码语言:javascript
复制
optimization: {
    splitChunks: {
      cacheGroups: {
        commons1: {
          name: 'commons1',
          chunks: 'all',
          minChunks: 1,
          test(module,chunks){
            for (const chunk of module.chunksIterable) {
              if (chunk.name && /(popup|content)/.test(chunk.name)) {
                   return true;
              }
            }
            return false;
          }
        },
        commons2: {
          name: 'commons2',
          chunks: 'all',
          minChunks: 1,
          test(module,chunks){
            for (const chunk of module.chunksIterable) {
              if (chunk.name && /(options|commons1)/.test(chunk.name)) {
                   return true;
              }
            }
            return false;
          }
        },
        commons3: {
          name: 'commons3',
          chunks: 'all',
          minChunks: 1,
          test(module,chunks){
            for (const chunk of module.chunksIterable) {
              if (chunk.name && /(bg|commons2)/.test(chunk.name)) {
                   return true;
              }
            }
            return false;
          }
        },
      }
    }
  },
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70722619

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档