html-webpack-tags-plugin icon indicating copy to clipboard operation
html-webpack-tags-plugin copied to clipboard

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

Open mwoz123 opened this issue 4 years ago • 2 comments

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:/

mwoz123 avatar Mar 05 '21 20:03 mwoz123

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?

jharris4 avatar Mar 06 '21 14:03 jharris4

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

mwoz123 avatar Mar 06 '21 20:03 mwoz123