shellscape / webpack-manifest-plugin

webpack plugin for generating asset manifests
MIT License
1.44k stars 185 forks source link

Generate with compilation object #137

Closed jscheid closed 3 years ago

jscheid commented 6 years ago

Hi, I'm looking after webpack-subresource-integrity. We've had several requests for a feature that would let people export the per-asset integrity values as JSON, but I think a better solution might be to make it easy to use your plugin together with ours.

One simple solution would be if you could pass the compilation object as an additional argument to generate. We'd then export a default generator function and advise people to use it like so:

new ManifestPlugin({
  generate: SriPlugin.manifestGenerator(),
})

Our generator function would find the integrity values from the compilation object and generate something like { path: '...', integrity: '...' } based on it.

What do you think?

mastilver commented 6 years ago

HI @jscheid

I think that sounds great!! :)

Anything we should add from https://github.com/danethurber/webpack-manifest-plugin#hooks-options to help you implement that?

jscheid commented 6 years ago

I guess if it had the original compilation asset that would be ideal. It would have to be the one from compilation.assets, not the one from compilation.getStats().toJson().assets because there isn't a good way yet for adding custom data to the stats JSON.

It's questionable though how useful this would be to others, and the distinction between "original" and "json" asset is confusing to anyone not familiar with Webpack internals. From that angle I'd say it would be enough to just pass the compilation object at the top level, but either way is fine.

ghost commented 5 years ago

I want to write a plugin to add data mapping entry points to chunk names using a very similar approach.

shellscape commented 3 years ago

We've added support for the beforeEmit hook in f62ca8b273dcba5911e5f08814595c949120b6af. Please see the Compiler Hooks section in the README.