解决webpack打包问题 通过npm install webpack webpack-cli -g全局安装了webpack后用webpack打包一个js文件执行命令webpack example.js -o app.js报错内容如下assets by status0bytes[cached]1assetWARNINGinconfiguration Themodeoption has not been set,webpack will fallback toproductionforthisvalue.Setmodeoption todevelopmentorproductionto enable defaultsforeach environment.You can alsosetit tononeto disable anydefaultbehavior.Learn more:https://webpack.js.org/configuration/mode/ERRORinmain Module not found:Error:Cant resolve example.js in F:\大三-上\web\vue Did you mean./example.js?Requests that should resolveinthe current directory need to startwith./.根据报错提示执行命令webpack ./example.js -o ./app.js依旧报错asset main.js15bytes[comparedforemit][minimized](name:main)./example.js67bytes[built][code generated]WARNINGinconfiguration Themodeoption has not been set,webpack will fallback toproductionforthisvalue.Setmodeoption todevelopmentorproductionto enable defaultsforeach environment.You can alsosetit tononeto disable anydefaultbehavior.Learn more:https://webpack.js.org/configuration/mode/webpack5.74.0compiledwith1warningin256ms解决这个问题需要两处配置package.json文件里scripts:{dev:webpack --mode development,build:webpack --mode production}webpack.config.js文件里如果没有这个文件可以在当前目录下自行创建module.exports{mode:development,// 设置mode development为开发环境production为生产环境};问题解决运行webpack ./example.js -o ./app.js得到如下结果asset main.js1.23KiB[emitted](name:main)./example.js67bytes[built][code generated]webpack5.74.0compiled successfullyin114ms然后app.js已经被处理过与原来的example.js大不相同了。参考链接https://blog.csdn.net/qq_34979346/article/details/99840181