How do you specify your index.html file?
gabaum10 opened this issue · 4 comments
I don't see anything in the docs about how to specify where the html file you want to copy lives. Do you plan on adding support for that? It's kind of limiting my usage of this plugin.
Sorry, I think you may have misunderstood the role of this plug-in, it is used to replace those resource links or string content within a html file, instead of replacing a html file, I hope you know this. As for the features you expect, there is no consideration to join, you can currently use other plugins instead, thank you!
No, I understand perfectly. There is absolutely nothing that says where that html file is pulled from. /src/file.html? How incredibly inflexible and basically unusable if you have any difference in your folder structure. I was hoping there was an option to specify which file to replace the text in, but I guess there isn't.
@gabaum10 I agree, the documentation is lacking; had the same question myself.
However, I studied iminif's howto project and was able to learn that html-replace-webpack-plugin works together with html-webpack-plugin, which itself allows you to specify the input and output filepaths:
module.exports = {
plugins: [
new HtmlWebpackPlugin(
{
filename: 'output.html',
template: 'src/inputTemplate.html',
inject: false,
minify: false
}),
new HtmlReplaceWebpackPlugin([
{
pattern: 'CACHEBUSTER',
replacement: Date.now().toString()
}
])
]
};
So, with that config:
-
The
filename
field specifies the built file (which in the above configuration is simply a direct duplicate of the original, because I didn't make HtmlWebpackPlugin apply any editing operations). This is the file that will be passed on in turn to HtmlReplaceWebpackPlugin to be re-processed either: in-memory (prior to being written to disk); or immediately after being written to disk (prompting a re-write of the file). I don't know exactly which. -
The
template
field specifies the input file (if you have an existing one that you want to use). HtmlWebpackPlugin would otherwise auto-generate a HTML file for you based on any resources handed to it by Webpack (eg. CSS, JS, IMG).
Hi. I have created a fork of this plugin, which does what @gabaum10 originally wanted.
https://github.com/AndrewLevada/html-replace-webpack-plugin