zoukankan      html  css  js  c++  java
  • Error: webpack.optimize.CommonsChunkPlugin has been removed

    最近使用webpack 进行react 依赖抽离时发现原本的webpack.optimize.CommonsChunkPlugin已经不能使用了
    在这里插入图片描述


    打包时提示


    
    Error: webpack.optimize.CommonsChunkPlugin has been removed, please use config.optimization.splitChunks instead.
    
    

    官方仔细一看文档发现

    The CommonsChunkPlugin has been removed in webpack v4 legato. To learn how chunks are treated in the latest version, check out the SplitChunksPlugin.

    原来是得学着使用SplitChunksPlugin来构建了,

    这个更是简单了,直接在module.exports增加如下案例代码即可

      optimization: {
        splitChunks: {
          cacheGroups: {
            vendor: {
              test: /[\/]node_modules[\/](react|react-dom)[\/]/,
              name: 'vendor',
              chunks: 'all',
            }
          }
        }
      }

    遗憾的是当时试着将依赖生成多个js文件并未成功

  • 相关阅读:
    css3 省略号
    js一些常用方法
    nth-child使用
    常见表单元素处理
    表单的基本使用
    web基本概念
    PHP数组
    PHP函数
    PHP错误处理
    PHP文件载入
  • 原文地址:https://www.cnblogs.com/dengxiaoning/p/12871793.html
Copyright © 2011-2022 走看看