doc/3.init.webpack.dev.config.md
1. - build
- add webpackConfig.dev.config file
```
const path = require('path');
const webpack = require('webpack');
const merge = require('webpack-merge'); // webpack 合并配置的方法
const baseConfig = require('./webpack.base.config'); // 基础配置
const config = merge(baseConfig, {
output: {
publicPath: '/' // 重新定义在 index.html srcipte src 中的资源访问路径
},
devServer: {
host: '0.0.0.0',
contentBase: '/', // 在我们启动的 web 服务下的根目录就可以访问初始路径
port: 9000,
hot: true,
open: true,
historyApiFallback: { // 在 404 的情况重定到指定的
index: path.join(__dirname, '../dist/index.html')
}
},
plugins: [
new webpack.HotModuleReplacementPlugin() // 在配置好 devServer 的内容之后,要使用 HMR 替换插件
]
})
module.exports = config
```
2. - package.json
```
"scripts": {
...
"dev": "webpack-dev-server --config build/webpack.dev.config.js"
...
},
```