一次create-react-app创建项目升级webpack的流水账

栏目: JavaScript · 发布时间: 7年前

内容简介:不再赘述为什么要升级webpack4,有兴趣的小伙伴可以看一下下面撸起袖子开干:克隆项目,新建分支

不再赘述为什么要升级webpack4,有兴趣的小伙伴可以看一下 知乎:如何评价webpack4

下面撸起袖子开干:

克隆项目,新建分支

git checkout -b feature_webpack_upgrade  
# 相当于以下两句的简写
git branch feature_webpack_upgrade  
git checkout feature_webpack_upgrade

升级 webpack

yarn add webpack webpack-dev-server webpack-cli

运行后报错:

Plugin could not be registered at 'html-webpack-plugin-before-html-processing'. Hook was not found.

报错信息表示插件 html-webpack-plugin-before-html-processing 有问题,然而 webpack 中并没有这个插件,google之后发现 github上 有对这个问题的讨论,所以升级插件:

yarn add react-dev-utils html-webpack-plugin

修改配置文件,交换以下两个插件位置 :

new HtmlWebpackPlugin({}), 

new InterpolateHtmlPlugin(env.raw),

继续运行,报错

TypeError: Cannot read property 'eslint' of undefined

升级 eslint 即可

yarn add eslint-loader

继续运行,报错:

missingDeps.some not a function

这个问题比较棘手,继续google之后找到原因 missingDeps.some not a function

yarn add react-dev-utils@6.0.0-next.3e165448

继续运行,报错:

Error: webpack.optimize.UglifyJsPlugin has been removed, please use config.optimization.minimize instead.

干掉被移除的插件 UglifyJsPlugin 即可, webpack4 生产模式下原生支持代码压缩和分割

继续运行,报错:

Chunk.entrypoints: Use Chunks.groupsIterable and filter by instanceof Entrypoint instead 
mini-css-extract-plugin

很明显, Entrypointmini-css-extract-plugin 提供了,查找之下发现 Chunk.entrypointsextract-text-webpack-plugin 提供,那么:

yarn remove extract-text-webpack-plugin
yarn add mini-css-extract-plugin

继续运行,报错:

Error: Chunk.initial was removed. Use canBeInitial/isOnlyInitial()

升级 webpack-manifest-plugin 即可。

运行通过,提交代码,PR。

所有问题都可以通过仔细阅读 error trace 加上善用google搞定。

收工~


以上所述就是小编给大家介绍的《一次create-react-app创建项目升级webpack的流水账》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Probability and Computing

Probability and Computing

Michael Mitzenmacher、Eli Upfal / Cambridge University Press / 2005-01-31 / USD 66.00

Assuming only an elementary background in discrete mathematics, this textbook is an excellent introduction to the probabilistic techniques and paradigms used in the development of probabilistic algori......一起来看看 《Probability and Computing》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

html转js在线工具
html转js在线工具

html转js在线工具

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试