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//生成文件小