Reputation: 1455
How do you setup webpack to watch and reload for HTML pages?
I'm using webpack 1.
I saw something about requiring index.html into your entry point.
That just doesn't feel right to me.
Upvotes: 1
Views: 78
Reputation: 21757
For direct reloading html file you might want to use HtmlWebpackPlugin.
For reloading page through changing its dependencies use the following:
You have to set a wepack.config.js in the directory of your html page.
Then you need to set any css, js, jsx file for compilation with the help of webpack dev server like the following:
var path = require('path');
var webpack = require('webpack');
var glob = require("glob");
var HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry: {
app: glob.sync('./css.css')
},
output: {
path: path.resolve(__dirname, 'dist/js/'),
filename: 'bundle.[name].js'
}
};
After that, you need to refer to this file in your html page. For example, in this case, you need to add in the html file
<head>
script src="../dist/js/bundle.css.js" ></script>
<head>
Then you need to run webpack dev server.
Upvotes: 1