jharris4 / html-webpack-tags-plugin

lets you define html tags to inject with html-webpack-plugin
MIT License
256 stars 31 forks source link

Can't add generated (not copied) by webpack script using glob #69

Open mwoz123 opened 3 years ago

mwoz123 commented 3 years ago

In my webpack configuration I'm using https://www.npmjs.com/package/webpack-merge-and-include-globally which concatenates number of legacy es5 global scripts into one (named es5-legacy-global-script<hash>.js )

My html-webpack-tags-plugin configuration is:

new HtmlWebpackTagsPlugin({ scripts: [{ glob: 'es5-legacy-global-script*.js', globPath: 'dist',  path:''}] });

because it's not a copied script doesn't exist before webpacks run. so I'm getting error:

[webpack-cli] { AssertionError [ERR_ASSERTION]: HtmlWebpackTagsPlugin.options.scripts object glob found no files ( es5-legacy-global-script*.js )

Workaround is to create that file (can be empty) in dist folder..

but this means that on git I should keep this file, which is a bad idea:(

Is there a way to fix it? ps: globalPath param is required:/

jharris4 commented 3 years ago

Hi! If I'm understanding correctly, you are trying to add an asset that doesn't exist when the build starts and is generated by webpack? This plugin expects all the assets to exist before the build starts...

Normally it is expected that all webpack generated files will already be handled by the html-webpack-plugin that this plugin is built on top of.

Also the fact that both this plugin and the webpack plugin you mentioned are using the processAssets webpack hook could make this complicated.

https://github.com/markshapiro/webpack-merge-and-include-globally/blob/4e3c0dc7d8be58dc106efc659cb836907e7ae780/index.js#L27

https://github.com/jantimon/html-webpack-plugin/blob/570f735c237d4a03a65622cfe64652431aca4132/index.js#L224

Have you considered filing an issue on the webpack-merge-and-include-globally repository to ask why the generated assets are not being output by html-webpack-plugin?

mwoz123 commented 3 years ago

Sure I'll. Just didn't understand why it couldn't be generated..