ITPub博客

首页 > 应用开发 > Node.js > 前端技术之:webpack热模块替换(HMR)

前端技术之:webpack热模块替换(HMR)

原创 Node.js 作者:liuchunrong 时间:2019-10-14 23:49:27 0 删除 编辑
第一步:安装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。
参考官网链接:
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.


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/69949941/viewspace-2659974/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-10-02

  • 博文量
    26
  • 访问量
    19153