一般开发时和发布时的配置文件会分离,所以在根目录下创建一个build文件夹来分离不同的配置并新建一些配置文件:
base.config.js
:公共依赖
prod.config.js
:发布依赖
dev.config.js
:开发时依赖
安装webpack-merge进行配置文件的拼接
npm install webpack-merge --save --dev
拼接baseConfig和pordConfig:
const uglifyjsWebpackPlugin = require('uglifyjs-webpack-plugin');
const webpackMerge = require('webpack-merge')
const baseConfig = require('./base.config.js')
module.exports = webpackMerge(baseConfig, {
plugins:[
new uglifyjsWebpackPlugin()
]
})
同时要改变输出路径:
output: {
path:path.resolve(__dirname , "../dist"),
filename: 'boundle.js'
},
网友评论