简体   繁体   中英

live html reload with webpack

sorry for the noob question (I'm still newbie with webpack) I'm interested in live reload my html, that means, everytime than I do a change in my html file my browser must show the latest changes, webpack has a nice feature than works for javascript, is possible use it with html?

just now I'm using this skeleton https://github.com/gaearon/react-hot-boilerplate for develop, yes I'm working with react but also I'm building a few static pages

I know about libs like live.js but I found it not so transparent: this reload my browser and this is empty for a few seconds, instead bracket (for html) and webpack (for js) are almost instantly and you dont feel the browser reload, an alternative like this outside of webpack also would be appreciate, thanks

After hours of searching google I finally found the answer. Just add this config:

devServer: {
  before(app, server) {
    const chokidar = require('chokidar');
    chokidar.watch('path/to/my-files/').on('all', function (event, path) {
      server.sockWrite(server.sockets, 'content-changed');
    });
  },
}

Found it on a blog here: https://daltontan.com/easiest-way-to-reload-webpack-dev-server-when-other-files-change/30

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM