jharris4 / html-webpack-tags-plugin

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

Glob & globPath incompatible with sourcePath #84

Closed neutraali closed 2 years ago

neutraali commented 2 years ago

Problem: sourcePath is incompatible with glob + globPath, which leads to builds and/or the DevServer not reacting to any changes. For example, using the following config:

new HtmlWebpackTagsPlugin({
    append: false, // Prepend vendors before app bundle
    hash: true,
    tags: {
        path: 'js',
        glob: '!(app).bundle.*.js',
        globPath: 'path/to/build/js',
        sourcePath: 'path/to/build'
    }
})

... Leads to the following error:

eisdir

... Which leads me to suspect sourcePath is meant for individual files, not directories or anything glob -related. Should there be a globSource or similar config entry available?

jharris4 commented 2 years ago

Hmm, I can't recall whether I've tried using the glob options together with the sourcePath option. A quick review of the code implies that you can specify sourcePath with glob, but then all found files will get the same sourcePath.

Can you provide some more explanation of what it is you are trying to accomplish?

Also, if you think something is not working as it should, it would be really helpful if you could add a test case similar to the ones here:

https://github.com/jharris4/html-webpack-tags-plugin/blob/bccd3e707ae8e04a791392dbd7cc0d3adfe2882c/spec/end_to_end.spec.js#L2443

neutraali commented 2 years ago

Right, so... Consider a folder called path/to/build/js with the following content:

app.bundle.296af3076e0ed3bfc6de.js
app.bundle.296af3076e0ed3bfc6de.js.map
language.bundle.71a7752cee0fd892f808.js
language.bundle.71a7752cee0fd892f808.js.map
vendor.bundle.71a7752cee0fd892f808.js
vendor.bundle.71a7752cee0fd892f808.js.map

... Using the config above, the idea would be to map/link vendor and language to their relevant (non-map) source files. This may or may not be an actually relevant issue, as it can probably also be handled by including it in watch -configuration of Webpack separately.

jharris4 commented 2 years ago

It looks like you're maybe trying to use this plugin to do things with webpack generated assets, and that's not what this plugin is designed for.

That said, if you're trying to somehow inject existing scripts as tags into your html, you'll need to make sure you copy the scripts and associated source map files using copy-webpack-plugin, so that they get served together from the same place.

usually your JS files will have a comment at the end with a path to the source map, something like this:

//# sourceMappingURL=app.bundle.296af3076e0ed3bfc6de.js.map

So long as the source map path is relative like this and you copy both the script and sourcemap to the same place, your sourcemaps should load properly.

neutraali commented 2 years ago

Cool, I can get on with this. Thanks for the snappy replies @jharris4!