chunkFilename – function doesn’t work – Webpack 4

Do you want to request a feature or report a bug?
no

What is the current behavior?
Error when function is used as chunkFilename option.

If the current behavior is a bug, please provide the steps to reproduce.

  • Create project that should have some chunks (something like System.import('./test.js').then(function module() { console.log('OK'); }); )
  • Set chunkFilename option to: function(){ return '[id].chunk.js'; }
  • Try to compile.

What is the expected behavior?
Chunk with name “{some_id}.chunk.js” should be generated.

If this is a feature request, what is motivation or use case for changing the behavior?
no

Please mention other relevant information such as the browser version, Node.js version, webpack version, and Operating System.
The problem is that chunkFilename is handled incorrectly in “JsonpMainTemplatePlugin.js” and all other templates (and maybe somewhere else to).
For example here:

const chunkFilename = mainTemplate.outputOptions.chunkFilename;

There should be something like:

const chunkFilename = typeof path === "function" ? mainTemplate.outputOptions.chunkFilename(....required arguments....) : mainTemplate.outputOptions.chunkFilename; 

Author: Fantashit

1 thought on “chunkFilename – function doesn’t work – Webpack 4

  1. hmm that’s true. For technically reasons chunkFilename can’t be a function. Do you want to send a PR disallowing it in the schema?

Comments are closed.