webpack: output.filename not working if function
Bug report
What is the current behavior?
When I use a function for output.filename it doesn’t work for my dynamic imports: they get emitted as 1.js, 2.js etc. with identical chunk value (whereas chunk name is correct)
In addition things get worse when I set optimization.runtime to single what results in even the entries being affected (only runtime.js is correct then).
The same filename code as string works without problems and emits foo.js, bar.js etc.
// working
filename: isProd ? '[name].[chunkhash].js' : '[name].js',
// not working
filename: data => isProd ? '[name].[chunkhash].js' : '[name].js',
If the current behavior is a bug, please provide the steps to reproduce.
- create
app.jswith dynamic imports
// app.js
console.log('[entry] app');
import(/* webpackChunkName: 'foo' */ './foo').then(mod => console.log(mod.default));
import(/* webpackChunkName: 'bar' */ './bar').then(mod => console.log(mod.default));
// foo.js
export default '[dynamic] foo';
// bar.js
export default '[dynamic] bar';
- change
output.filenameto function and run webpack via node api
What is the expected behavior?
I expect no difference when filename function returns the same string I’ve used for filename string before.
Other relevant information: webpack version: 4.29.6 Node.js version: 10.15.0 Operating System: macOS Mojave (10.14) Additional tools: -
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 2
- Comments: 18 (10 by maintainers)
@SassNinja i think we can make
chunkFilenameas FunctionAny update on this?
@sokra would be awesome if you can clarify things a bit (why
chunkFilenamecan’t be a function)Only the
runtimechunk is affected byoutput.filename. The other chunks are affected byouput.chunkFilename.If
output.filenameis a string,output.chunkFilenamedefaults to the same string. If it’s a functionoutput.chunkFilenamedefaults to[id].js. You cannot provide a function tooutput.chunkFilename.