拆分配置
根据mode模式的不同 可以将webpack.config.js拆分开来
webpack.base.config.js 基本配置
module.exports = {
}
webpack.pro.config.js 生产环境
const baseConfig = require('webpack.base.config.js')
const proConfig = {
mode:"production",
}
webpack.dev.config.js 开发环境
const baseConfig = require('webpack.base.config.js')
const devConfig = {
mode:"development",
}
合并配置
将单独设置的配置 与基本配置合并
- 下载webpack-merge
npm install webpack-merge -D
const baseConfig = require('webpack.base.config.js')
const { smart } = require('webpack-merge')
const proConfig = {
mode:"production",
}
module.exports = smart(baseConfig,proConfig )
const baseConfig = require('webpack.base.config.js')
const { smart } = require('webpack-merge')
const devConfig = {
mode:"development",
}
module.exports = smart(baseConfig,devConfig )
设置脚本
package.json
{
"scriptd":{
"build": "webpack --config webpack.pro.config.js",
"dev": "webpack --config webpack.dev.config.js",
}
}
|