1

Question

I need to exclude multiple files from webpack optimization from splitchunk plugin.

What I've tried

const excludedFiles = ['file 1', 'file 2'];

module.exports = {
  //...
  optimization: {
    splitChunks: {
      chunks (chunk) {
        // exclude `my-excluded-chunk`
        return !excludedFiles.includes(chunk.name);
      }
    }
  }
};

Result

It seems the files are not excluded.

How can achieve that?

1 Answers1

0

You cannot do that. Note that chunk is not equal to a file. Modules (1 module ~ 1 file) are combined into chunks, chunks into chunk groups and groups into chunk graph. So, a filename doesn't mean it is chunk.

The options chunks in optimization.splitChunks means that which chuck to exclude or include during the optimization process. So, it means you can exclude a chunk but not individual file.

If you want to do what you are trying to achieve then, using externals is a way to go. It is not exactly same but almost equivalent to your needs.

Harshal Patil
  • 17,838
  • 14
  • 60
  • 126