webpack官网:https://webpack.js.org/webpack
全局安装webpack
cnpm i -g webpack webpack-cli
建立index.js
console.log('hello webpack')//示例:建议写es5语法可正常运行,es6须要babel后面作笔记会写
cmd运行
webpack index.js//------>生成文件夹dist,生成文件main.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:
官网mode详解:https://webpack.js.org/configuration/mode/es6
下面两种生成方式无警告(加上mode,默认mode为none)web
开发模式development
webpack index.js --mode development//生成文件比较大
生产模式production
webpack index.js --mode production//生成文件小