引用:webpack-dev-server、webpack-dev-middleware、webpack-hot-middleware
webpack-dev-server
vi webpack.config.js
const path = require('path'); ... module.exports = { ... devServer: { contentBase: path.resolve(__dirname, './dist'), host: '192.168.0.247', compress: true, port: 8888, historyApiFallback: true, } ... }
注:
historyApiFallback
可以保证类似http://localhost:8885/aaaaaaaaaaa
的请求返回跟http://localhost:8885/
一样的页面,这样才能用同一个js
根据路径的不同去往不同的路由
vi package.json
{ ... "scripts": { ... "debug": "webpack-dev-server --mode development" ... } }
- 效果
这种方式的热更新会刷新页面
,对react
来说,其React Tool
插件是有效的
-
webpack-dev-middleware
、webpack-hot-middleware
html-webpack-plugin
自动生成
html
html-webpack-plugin
网友评论