skozin / webpack-path-rewriter

Webpack plugin for replacing resources' paths with public ones
67 stars 5 forks source link

Does not rewrite html file contents on webpack watch/change :( #6

Open AndrewRayCode opened 9 years ago

AndrewRayCode commented 9 years ago

If you change any source file while webpack is running, the plugin does not rewrite the paths in the built html file. You have to stop and re-run webpack.

AndrewRayCode commented 9 years ago

Appears to be because you clear the modules after you process them? https://github.com/skozin/webpack-path-rewriter/blob/master/es6/index.js#L357

skozin commented 9 years ago

No, that's because the loader doesn't get invoked unless you change the file it is rewriting. This is how Webpack currently works. So, when you change some other file, the hashes become different, but webpack-asset-rewriter has no chance to react to these changes.

Since this module consists of not only loader, but also a plugin, it might be possible to auto-update the target file, but I'm not sure (and have no time to experiment with this now). For now, the best strategy is to disable hashing during development. Eventually, this will be covered by examples in this repo, but until that you can find an example here. That setup supports hashing in production mode, source maps, livereload and hot stylesheets replacement.

Another thing that you may want to enable in development is the includeHash constructor option. It makes compilation hash dependent on the contents of all files being rewritten, so your app will auto-reload when any of these files (say index.html) changes. But this should be disabled during production build, as you definitely don't want the hash of your JS bundle to depend on the contents of some file that is not included in that bundle.

AndrewRayCode commented 9 years ago

hmm - disabling hashing in dev sounds like a good idea. i'll try that and see if the whole thing works with that in place

skozin commented 9 years ago

BTW, removing the line you linked in the previous comment might do the trick, but this will require some other changes in the logic of both loader and plugin, and a fair amount of testing. I'm not sure that it will not break something else)