前端技術之:webpack熱模塊替換(HMR)

第一步:安裝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.
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章