cascornelissen / svg-spritemap-webpack-plugin

SVG spritemap plugin for webpack
MIT License
211 stars 51 forks source link

Failing to clean dummy-chunk on some occasions #81

Closed Maiquu closed 5 years ago

Maiquu commented 5 years ago

Using webpack 4.x, svg-spritemap-webpack-plugin 3.3.5, Webpack configuration is something like this:

module.exports = {
      mode: "development",
      output: {
        path: path.resolve(context,"./dist"),
        filename: "code.bundle.js",
        //chunkFilename: "[id].js",
        publicPath: ""
      },
      plugins: [
        new SVGSpritemapPlugin('./editor/assets/svg/*.svg',{
          output: {
            filename: "symbol-defs.svg",
            svg4everybody: false
          },
          sprite: {
            prefix: "icon-"
          }
        })
      ]
  }

If I define output.filename as a string without any placeholders, dummy module's chunk uses that string as a postfix to define its filename. This causes the internal check to remove the dummy chunk fail.

compilation.chunks.forEach((chunk) => {
  if ( chunk.name !== outputOptions.chunk.name ) {
    return;
  }
  // chunk.name is 'spritemap' while chunk filename is 'spritemap.code.bundle.js' 
  chunk.files.filter((file) => {
    return [`${chunk.name}.js`, `${chunk.name}.js.map`].includes(file);
  }).forEach((file) => {
    delete compilation.assets[file];
  });
});

It can be easily fixed if you define a output.filename with placeholders or define output.chunkFilename. Latter is the one I preffered. Not sure if this is considered nitpicking.

cascornelissen commented 5 years ago

@Maiquu, I'm not 100% sure what you're trying to say and I think this is caused by the fact that both the main webpack object and the plugin options take an output.filename... Could you clear that up a bit?

Maiquu commented 5 years ago

The output.filename I mentioned above is from the main webpack object. Sorry for the confusion.

cascornelissen commented 5 years ago

Ah, I get it now and it should be fixed in master, in 8f4090e96 specifically. Could you try installing it directly from there and reporting if that fixes it for you?

npm install --save-dev cascornelissen/svg-spritemap-webpack-plugin#master
Maiquu commented 5 years ago

Yep, no issues spotted. Thanks for your quick response.

cascornelissen commented 5 years ago

Thanks for your quick response as well! I'll leave the issue open until I release a new patch version containing the fix ✌️

cascornelissen commented 5 years ago

@Maiquu, a fix for this issue has been released in version 3.3.6 🚀