温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

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

发布时间:2020-07-07 10:40:47 来源:网络 阅读:322 作者:popgis 栏目:web开发

第一步:安装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/hot-module-replacement/

https://github.com/webpack-contrib/webpack-hot-middleware

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.


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI