使用webpack-merge 合并配置
然后对应script为:
build:dev webpack --config webpack.dev.config.js
build webpack --config webpack.prod.config.js
// webpack.base.config.js const path = requrie('path); const HtmlWebpackPlugin = require('html-webpack-plugin'); module.exports = { entry: { main: './src/index.js' }, output: { filename: '[name].js', path: path.resolve(__dirname, 'dist') }, plugins: [ new HtmlWebpackPlugin({ template: './src/index.html' }) ] } // webpack.dev.config.js const baseConfig = require('./weback.base.config.js'); const { smart: merge } = require('webpack-merge'); const devConfig = { mode: 'development' // 开发环境配置.... } module.export = merge(baseConfig, devConfig); // webpack.prod.config.js const baseConfig = require('./weback.base.config.js'); const { smart: merge } = require('webpack-merge'); const prodConfig = { mode: 'production' // 生产环境配置.... } module.export = merge(baseConfig, prodConfig );
标签:const,require,合并,webpack,js,merge,Webpack,拆分,config From: https://www.cnblogs.com/shaoyunfeng93/p/16731021.html