I have the webpack-dev-server with --hot
enabled, and it works great ... for Javascript files. If I:
/src/someFile.js
with the code document.write("Foo");
<script>
referencing /src/someFile.js
to my index.html
/src/someFile.js
to document.write("Bar");
However, if I have <p>Foo</p>
on my index.html
file, and change it to <p>Bar</p>
, I don't see the change. If I refresh the page I do see the change though, so I know webpack is serving index.html
; it's just not hot-swapping it when I save the file.
Does anyone know how I can fix webpack-dev-server
to automatically update my HTML in response to file changes?
The HtmlWebpackPlugin simplifies creation of HTML files to serve your webpack bundles. This is especially useful for webpack bundles that include a hash in the filename which changes every compilation.
webpack-dev-server is Webpack's officially supported CLI-based tool for starting a static server for your assets. While you don't need any CLI tools to use Webpack, webpack-dev-server gives you a single command that starts a static server with built-in live reload.
Run the Webpack dev server Because we are using html-weback-plugin , it will create an index. html file and include the bundled file main. js into the script tags.
This solution should work like a charm for you. In your example the steps are:
npm install --save-dev raw-loader
Add this to your webpack.config loaders section...
{
test: /\.html$/,
loader: "raw-loader"
}
require('index.html');
line to the top of /src/someFile.js
.Basically you're just making webpack aware of index.html so that it watches for changes. This is just a quick fix for your particular problem but for anyone interested in the more in-depth 'why' of this solution refer to the more thorough explanation linked above.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With