第一步:安裝HMR中間件:
npm install --save-dev webpack-hot-middleware
第二步:webpack配置中引入webpack對象
const webpack = require('webpack’);
第三步:增加devServer配置項:
hot: true
第四步:增加熱模塊替換插件:
new webpack.HotModuleReplacementPlugin()
注意:
1、ExtractTextPlugin插件可能會導致HMR無效。
另外,還可以通過使用web-dev-server —hotOnly參數來啓用HMR。
參考官網鏈接:
https://webpack.js.org/guides...
https://github.com/webpack-co...
React、Vue、Angular相關技術,請參考以下內容:
- React Hot Loader: Tweak react components in real time.
- Vue Loader: This loader supports HMR for vue components out of the box.
- Elm Hot Loader: Supports HMR for the Elm programming language.
- Angular HMR: No loader necessary! A simple change to your main NgModule file is all that's required to have full control over the HMR APIs.