webpack运行webpack .\src\main.js .\dist\bundle.js打包出错

打包的命令格式:webpack 要打包的未年检的路径  打包好的输出文件的路径

运行webpack .\src\main.js .\dist\bundle.js

提示错误,错误信息如下:

WARNING in configuration
The 'mode' option has not been set, webpack will fallback to 'production' for this value. Set 'mode' option to 'development' or 'production' to enable defaults for each
environment.
You can also set it to 'none' to disable any default behavior. Learn more: https://webpack.js.org/configuration/mode/

ERROR in multi ./src/main.js ./dist/bundle.js
Module not found: Error: Can't resolve '.\dist\bundle.js' in 'E:\Repositories\Aliyun University\01.webpack-study'
@ multi ./src/main.js ./dist/bundle.js main[1]

 解决方法1:

将上面webpack命令改为webpack ./src/main.js --output-filename ./dist/murenziwei.js --output-path . --mode development,解决

  • --output-filename:设置要打包的文件目录
  • --output-path:打包文件放置的文件目录
  • --mode:告诉程序,在当前目录,我是属于开发状态development

解决方法2:

在配置文件中,需要手动指定 入口 和 出口
1 module.exports = {
2      
3     // 在配置文件中,需要手动指定 入口 和 出口
4     entry:path.join(__dirname,'./src/main.js'),//入口,表示,要使用 webpack 打包哪个文件
5     output:{//输出配置相关的配置
6         path:path.join(__dirname,'./dist'),//指定 打包好的文件,输出到哪个目录中去
7         filename:'bundle.js' //这是指定 输出的文件的名称
8     }
9 }

打包的命令格式:webpack

参考博客:https://www.cnblogs.com/murenziwei/p/10328813.html

猜你喜欢

转载自www.cnblogs.com/songsongblue/p/11756216.html