webpack学习笔记 (三) webpack-dev-server插件和HotModuleReplacementPlugin插件使用

 

webpack-dev-server插件

webpack-dev-server是webpack官方提供的一个小型Express服务器。使用它可以为webpack打包生成的资源文件提供web服务。

webpack-dev-server 主要提供两个功能:

  • 为静态文件提供服务
  • 自动刷新和热替换(HMR)

HotModuleReplacementPlugin插件

HotModuleReplacementPlugin主要用于代码热替换(具体用途还不清楚,因为没有研究通透吧)

 

一、webpack-dev-server插件说明

安装:

在cmd中输入npm webpack-dev-server -g执行;

启动:

在cmd中输入 webpack-dev-server执行;

 

额外参数配置

在webpack.config.json中增加devServer配置项

配置参数说明如下:

  • --content-base <file/directory/url/port>: base path for the content.
  • --quiet: don’t output anything to the console.
  • --no-info: suppress boring information.
  • --colors: add some colors to the output.
  • --no-colors: don’t use colors in the output.
  • --compress: use gzip compression.
  • --host <hostname/ip>: hostname or IP. 0.0.0.0 binds to all hosts.
  • --port <number>: port.
  • --inline: embed the webpack-dev-server runtime into the bundle.
  • --hot: adds the HotModuleReplacementPlugin and switch the server to hot mode. Note: make sure you don’t add HotModuleReplacementPlugin twice.
  • --hot --inline also adds the webpack/hot/dev-server entry.
  • --public: overrides the host and port used in --inline mode for the client (useful for a VM or Docker).
  • --lazy: no watching, compiles on request (cannot be combined with --hot).
  • --https: serves webpack-dev-server over HTTPS Protocol. Includes a self-signed certificate that is used when serving the requests.
  • --cert--cacert--key: Paths the certificate files.
  • --open: opens the url in default browser (for webpack-dev-server versions > 2.0).
  • --history-api-fallback: enables support for history API fallback.
  • --client-log-level: controls the console log messages shown in the browser. Use errorwarninginfo or none.

webpack-dev-server相关介绍请参见这里

 

HotModuleReplacementPlugin 

 (后续补充吧)

转载于:https://www.cnblogs.com/sunflowerGIS/p/6821792.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值