HenrikJoreteg / hjs-webpack

Helpers/presets for setting up webpack with hotloading react and ES6(2015) using Babel.
1.79k stars 127 forks source link

Support for sending non-HMR file change events to the client #247

Open michaek opened 8 years ago

michaek commented 8 years ago

This is supporting the case of files modified by plugins (CopyWebpackPlugin, HtmlWebpackPlugin) that can't be sent via HMR because they're not required in a bundle. A simple case is documented here.

The config might look something like

if (config.devServer) {
    config.devServer.customWatch = {
        jade: 'src/**.jade'
    }
}

and it's assumed that sending the object key and changed file path to the client is sufficient to respond with something like

if (NODE_ENV === "development") {
    var webpackHotMiddlewareClient = require('webpack-hot-middleware/client')

    webpackHotMiddlewareClient.subscribe((e) => {
        if (e.type === 'jade') {
            window.location.reload()
        }
    })
}

The approach is currently naive (I've even left out the chokidar dependency!) I'm just hoping to start a discussion about solving a case that doesn't fit within HMR but nonetheless seems to cause a certain amount of headache.

jrmcdona commented 6 years ago

I am copying over some LESS files to my dist folder. Would be great if I can change my LESS and have HMR. Has anyone go that working??

michaek commented 6 years ago

@jrmcdona It's probably preferable to use the less loader and include your output CSS in the Webpack bundle. The approach described here would be best for files that can't be addressed as modules by loaders (and thus make use of hot module reloading).