webpack4自动打包爬坑

为什么引用/bundle.js?根目录下面没有bundle.js啊?
我们先看打包结果:
在这里插入图片描述
这里指出了,webpack输出的文件被托管在localhost:8080的根目录/下面

这里有个巨坑:

输入npm run dev以后报错
在这里插入图片描述
google了一下发现问题所在:

问题解决参考: Error: Cannot find module ‘webpack-cli/bin/config-yargs’ #1948
If you upgrade webpack to 5. *, and webpack cli to 4. *, an error will be reported:
Error: Cannot find module ‘webpack-cli/bin/config-yargs’
Temporary solution: Back off webpack cli to version 3. * for example:
“webpack-cli”: “^ 3.3.12”

果然,我的项目是webpack-cli4.5,是版本问题
在这里插入图片描述

解决:

卸载当前的 webpack-cli npm uninstall webpack-cli

安装 webpack-cli 3.* 版本 npm install webpack-cli@3 -D

猜你喜欢

转载自blog.csdn.net/dyw3390199/article/details/113833676