webpack 对 development 和 production 进行区分打包

./build

- build
	- webpack.common.js
	- webpack.dev.js
	- webpack.prod.js

webpack.common.js

module.exports = {
  entry: 
  output: 
  plugins: 
  module: 
  ...
}

webpack.dev.js

const { merge } = require('webpack-merge')
const commonConfig = require('./webpack.common')

const devConfig = {
  mode: 'development',
  devtool: 
  devServer: 
  plugins: 
  ...
}

module.exports = merge(commonConfig, devConfig)

webpack.prod.js

const { merge } = require('webpack-merge')
const commonConfig = require('./webpack.common')

const prodConfig = {
  mode: 'production',
  devtool: 
  ...
}

module.exports = merge(commonConfig, prodConfig)

package.json

{
  "scripts": {
    "serve": "webpack-dev-server --config ./build/webpack.dev.js",
    "build": "webpack --config ./build/webpack.prod.js"
  },
}
上一篇:java – 如何在生产代码中考虑单例?


下一篇:webpack打包The 'mode' option has not been set,错误提示