shellscape / webpack-manifest-plugin

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

Merge with existing manifest.json? #42

Closed ivancuric closed 7 years ago

ivancuric commented 7 years ago

Any ideas on how to merge with an existing manifest.json generated by other processes?

mastilver commented 7 years ago

Would doing:

{
  cache: JSON.parse(fs.readFileSync(...))
}

be enough or should we add an options to handle that?

cc @gmac

gmac commented 7 years ago

This is actually a fairly well-defined use case in multi-compiler architectures where we want a single manifest that documents output from all compilers. This can be achieved by passing a shared cache object to all plugin instances, such as:

var manifest = {};
var compiler1 = { ..., plugins: [ new WebpackManifestPlugin({ cache: manifest }) ] };
var compiler2 = { ..., plugins: [ new WebpackManifestPlugin({ cache: manifest }) ] };

Note that this pattern requires a single object instance to be shared; the system won't work as expected if you pass unique object clones to each plugin instance.

mastilver commented 7 years ago

@gmac Yeah I got that, but do you think the code I posted above is alright to handle merging with an existing manifest.json in the case of a single compiler?

gmac commented 7 years ago

@mastilver yep, looks right to me!

mastilver commented 7 years ago
module.exports = {
    // ...
    plugins: [
      new ManifestPlugin({
        cache: JSON.parse(fs.readFileSync(path.join(__dirname, 'manifest.json'))
      })
    ]
};