webpack4 配置文件分离
webpack4 配置文件分离
关于mode- webpack根据开发和生成环境一般可以将配置文件拆分,拆分dev和prod两种环境
|- package.json |- /build |- webpack.base.js |- webpack.dev.js |- webpack.prod.js
- 在scripts里修改相应的命令
"dev": "webpack-dev-server --config build/webpack.dev.js", "build": "webpack --config build/webpack.prod.js"
- 使用
webpack-merge
,用以合并通用配置文件与开发环境配置文件
// webpack.dev.js const path = require('path'); const webpack = require('webpack'); const merge = require('webpack-merge'); const baseWebpackConfig = require('./webpack.base'); module.exports = merge(baseWebpackConfig, { mode: 'development', devServer: { host: '127.0.0.1', port: 80, contentBase: path.join(__dirname, 'dist'), open: false, hot: false, disableHostCheck: true, proxy: {}, before () {} }, plugins: [ // 启用 HMR new webpack.HotModuleReplacementPlugin({}) ] });
// webpack.prod.js const baseWebpackConfig = require('./webpack.base'); module.exports = merge(baseWebpackConfig, { mode: 'production' });
相关推荐
不知道该写啥QAQ 2020-11-12
webfullStack 2020-11-09
Yvettre 2020-09-15
想做大牛的蜗牛 2020-10-30
gloria0 2020-10-26
gaojie0 2020-09-11
SelinaChan 2020-08-14
不知道该写啥QAQ 2020-08-09
gloria0 2020-08-09
不知道该写啥QAQ 2020-08-02
hline 2020-07-29
SelinaChan 2020-07-28
wangdianyong 2020-07-23
webpackvuees 2020-07-23
yqoxygen 2020-07-20
不知道该写啥QAQ 2020-07-18
waterv 2020-07-18
81463166 2020-07-17