Closed artivilla closed 4 years ago
I have this issue as well. The main blocker for me is that when you have enough entry points, the names of chunks which need to be loaded for multiple entry points truncate, so I can't use the name to understand which file goes to which entry point. I tried to specify my own generate function to add the entry point names to the output, but it doesn't seem to be available in the FileDescriptor type or the Chunk type. Is there any way that we can have this information available to us?
I was able to find the entry point in the generate
data after all, using fancy node debugging. My ManifestPlugin call now looks like this:
new ManifestPlugin({
generate: (seed, files) =>
files.reduce((manifest, file) => {
const fileData = { path: file.path };
if (file.chunk && file.chunk.groupsIterable) {
fileData.entries = [];
for(group of file.chunk.groupsIterable) {
if(group.options && group.options.name) {
fileData.entries.push(group.options.name);
}
}
}
return {
...manifest,
[file.name]: fileData
};
}, seed)
})
To generate a manifest like
{[entry_name]: ['ordered.js', 'list.js', 'of.js', 'chunks.js']}
I've got the following options.generate
:
(seed, files) => {
const entrypoints = new Set()
files.forEach(
(file) => ((file.chunk || {})._groups || []).forEach(
(group) => entrypoints.add(group)
)
)
const entries = [...entrypoints]
const entryArrayManifest = entries.reduce((acc, entry) => {
const name = (entry.options || {}).name
|| (entry.runtimeChunk || {}).name
const files = [].concat(
...(entry.chunks || []).map((chunk) => chunk.files)
).filter(Boolean)
return name ? {...acc, [name]: files} : acc
}, seed)
return entryArrayManifest
}
This results in something like
{
"foo": [
"vendors~bar~foo.a1258721c436b463b51d.js",
"foo.78f40b8c23cc6cbf3fa7.js"
],
"bar": [
"vendors~bar~foo.a1258721c436b463b51d.js",
"bar.a07432c2585ba2ae3d31.js"
]
}
which is pretty much what is what webpack outputs:
Entrypoint foo = vendors~bar~foo.a1258721c436b463b51d.js foo.78f40b8c23cc6cbf3fa7.js
Entrypoint bar = vendors~bar~foo.a1258721c436b463b51d.js bar.a07432c2585ba2ae3d31.js
EDIT: none of the entryPointInstance.files
have the output.publicPath prepended. You may have to prepend the public paths manually.
@SKalt is ._groups
coming from lodash
? i can't find any documentation on that function. only ._groupBy
_groups is an array property of each file object emitted by webpack.
@SKalt I think Your script should be included as a helper parameter in manifest plugin. Great work!
generate
now takes a entrypoints
parameter
fixed by #192
For future reference: I built this generator module on top of this module +1 year ago, partly based on the ideas in https://github.com/danethurber/webpack-manifest-plugin/issues/181#issuecomment-445277384: https://github.com/Sydsvenskan/node-asset-versions/blob/master/example/webpack.config.js with generator method being defined here: https://github.com/Sydsvenskan/node-asset-versions/blob/a63b074cf03327a2a9b4e4a355432f96a9b8d4f1/lib/manifest-generator.js#L11-L21
webpack version
"webpack": "4.22.0",
Currently the manifest file only generates the following format for multiple entries and the default split chunks configuration:With splitting the vendors, the entrypoints definitely output a list of chunks associated per entry:
Any way I can get the entire list added to the manifest?