asfktz / autodll-webpack-plugin

Webpack's DllPlugin without the boilerplate
MIT License
1.46k stars 81 forks source link

Incompatibility with webpack-manifest-plugin #58

Open sentience opened 7 years ago

sentience commented 7 years ago

We use https://github.com/danethurber/webpack-manifest-plugin to output a JSON manifest of source filenames to output filenames, which our application then uses to write the <script> and <link> tags, and other references to Webpack-compiled assets into our server-side HTML templates.

Using the manual setup for DllPlugin, this meant we were producing two JSON manifest files: one for the DLL build, and one for the main build.

With autodll-webpack-plugin, I can see the JSON manifest file generated by webpack-manifest-plugin for the DLL build gets written to the cache directory (along with the JavaScript bundle and the DllPlugin manifest file), but that file doesn't make it into the final Webpack output; only the JSON manifest file generated by webpack-manifest-plugin for the main build is output.

Since the file is sitting there in the cache directory, I'm hoping there is some easy way to support plugins that generate additional assets on output.

TomiHiltunen commented 6 years ago

Same problem here.

coagit commented 6 years ago

In order to get around this issue you can put webpack-manifest-plugin as a plugin in the auto dll. Just use a different name for the dll manifest so it won't overwrite your main manifest file.

...

plugins: [
  new AutoDllPlugin({
    entry: {...},
    plugins: [new WebpackManifestPlugin({fileName: 'dll.manifest.json'})]
  })
]

...

Then you will have two manifest files which can be merged somehow, or used separately.

stephencookdev commented 6 years ago

You can generate just 1 manifest file by adding a custom generate function

const seed = {};
const generate = (_, files) => files.reduce((_, { name, path }) => {
  // modify the shared seed object, so as to share it between the main and
  // DLL compiler instance
  seed[name] = path;
  return seed;
}),

module.exports = {
  plugins: [
    new WebpackManifestPlugin({
      generate,
      seed
    }),
    new AutoDllPlugin({
      plugins: [new WebpackManifestPlugin({
        generate,
        seed,
        fileName: '_throwaway.json'
      })]
    })
  ]
};

Still a bit hacky 😞 but generates 1 correct manifest file

In theory just doing the shared seed thing should solve the issue, but I'm guessing that something is causing the AutoDllPlugin's WebpackManifestPlugin instance to run first, but then output last (causing the staler manifest file to overwrite the newer file - hence the need for the _throwaway.json file)