mzgoddard / hard-source-webpack-plugin

https://www.npmjs.com/package/hard-source-webpack-plugin
ISC License
2.71k stars 160 forks source link

Run only on cold build #433

Open Akryum opened 6 years ago

Akryum commented 6 years ago

Using webpack-dev-server in development mode, it would be nice to only use hard-source for the cold build, and skip it when doing hot-reloads. Otherwise the extra amount of work done by hard-source makes the hot-reload much slower (and fast hot-reloading times are important in development).

dreyks commented 6 years ago

yes! i wanted to suggest just the same. on my setup hard source shaves off 80% of initial wds build time but the incremental builds are 2-3 times slower (3 sec vs 1 sec) with hard source since it has to read in all the cache

dreyks commented 6 years ago

i've made a workaround to make HSWP run only on initial WDS build

// in your webpack config
class HardSourceWDSPatchPlugin {
  apply(compiler) {
    compiler.hooks.invalid.tap('HardSourceWDSPatchPlugin', () => {
      compiler.hooks.watchRun.taps = compiler.hooks.watchRun.taps
        .filter((tap) => !tap.name.includes('HardSource'))
    })
  }
}

module.exports = {
  plugins: [
    new HardSourceWDSPatchPlugin()
  ]
}

this is a rather hacky monkeypatch but it works (only for Webpack 4 i suppose since I've used the new tap API directly)

@mzgoddard if you're interested I can try making a PR with a more robust solution

MateusDantas commented 5 years ago

Hello @dreyks I'd be interested in that. Can you elaborate more on your solution? It did not work here for me, hard source is still being run on WDS

dreyks commented 5 years ago

yeah... I've dropped this monkeypatch some time ago - the incremental builds were still slow with HSWP. I've stopped using HSWP for WDS altogether

MateusDantas commented 5 years ago

So what did you ended up doing? I like HSWP because it makes the initial build way faster (around 80% if I don't use it), but the subsequent builds using hot reloader are significantly slower.

dreyks commented 5 years ago

I'm using HSWP for non-WDS and production builds. It's sad to lose the initial build time (around 80% too) but I rarely restart wds