一次create-react-app创建项目升级webpack的流水账
不再赘述为什么要升级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 [email protected]
继续运行,报错:
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
很明显,Entrypoint
由mini-css-extract-plugin
提供了,查找之下发现Chunk.entrypoints
由extract-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搞定。
收工~
相关推荐
hline 2020-07-29
不知道该写啥QAQ 2020-11-12
webfullStack 2020-11-09
Yvettre 2020-09-15
想做大牛的蜗牛 2020-10-30
gloria0 2020-10-26
gaojie0 2020-09-11
SelinaChan 2020-08-14
不知道该写啥QAQ 2020-08-09
gloria0 2020-08-09
不知道该写啥QAQ 2020-08-02
SelinaChan 2020-07-28
wangdianyong 2020-07-23
webpackvuees 2020-07-23
yqoxygen 2020-07-20
不知道该写啥QAQ 2020-07-18
waterv 2020-07-18
81463166 2020-07-17