webpack安装大于4.x版本(没有配置webpack.config.js)

时间:2022-09-22 12:06:23

webpack安装大于4.x版本(没有配置webpack.config.js)

webpack 输出参数-o 高版本 

如果安装的webpack版本大于4+,还需要安装webpack-cli.在没有配置webpack.config.js之前,还需要配置输出参数

webpack ./src/main.js ./dist/bundle.js   //没有配置输出参数 -o
webpack安装大于4.x版本(没有配置webpack.config.js)
/没有配置输出参数 -o

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 'D:....\webpack-test2'

@ multi ./src/main.js ./dist/bundle.js main[1]

要解决这个问题,在打包指令中加入-o即

webpack安装大于4.x版本(没有配置webpack.config.js)
配置输出参数 -o
webpack ./src/main.js -o ./dist/bundle.js //加入-o指令
webpack ./src/main.js -o ./dist/bundle.js //加入--mode development可去掉屎黄色的警告

最好的解决方案:选择低于4.0的版本,无需安装webpack-cli,且可以直接输入输出

webpack ./src/main.js ./dist/bundle.js
webpack安装大于4.x版本(没有配置webpack.config.js)
低版本webpack打包