更新
npm install webpack现在安装默认4.x版本

1 webpack-cli(必须安装 新加cli脚手架 功能很强)

2默认配置,入口文件默认src/index.js,输出默认dist/main.js o配置其实很鸡肋

var path = require(‘path’)
var webpack = require(‘webpack’)
module.exports = {
entry: path.resolve(‘’, ‘./src/index.js’),
output: {
path: path.resolve(‘’, ‘./dist’),
filename: ‘[name].js’,
},
optimization: {
minimize: true
},
mode: ‘none’,
}

3 各种配件升级,各种loader升级

4 增加mode配置

两种值development | production 根据这俩个值做一些单独配置 还有none什么都不设置
官方process.env.NODE_ENV 获取当前环境
const NODE_ENV = process.env.NODE_ENV || ‘development’;
module.exports = {
mode: NODE_ENV,
entry: {
if(process.env.NODE_ENV === ‘development’){
//开发环境 do something
}else{
//生产环境 do something
}
用法webpack —mode=production
webpack.config.js中mode
package.json中script脚本命令

5压缩方法改变

原来
plugins: [
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
}
})
]
现在
optimization: {
minimize: true
},