Skip to content

output.chunkFilename does not accept a function (according to the validation) #9542

Description

@nschipperbrainsmith

Bug report

What is the current behavior?
Currently output.chunkFilename doesn't support a function yet: https://github.com/webpack/webpack/blob/master/lib/TemplatedPathPlugin.js when reading the TemplatedPathPlugin showed that line https://github.com/webpack/webpack/blob/master/lib/TemplatedPathPlugin.js#L143 simply fills the chunkFilename with the filename if it's left empty.

const chunkFilename = outputOptions.chunkFilename || outputOptions.filename;

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

This works fine:

webpackConfig
    .mode('production')
    .devtool(options.productionSourceMap ? 'source-map' : false)
    .output
    .filename((chunkData) => {
       return chunkData.chunk.name === 'vendor' ? 'js/[name].js': 'js/[id].[contenthash:8].js';
    })

This throws an error:

 webpackConfig
    .mode('production')
    .devtool(options.productionSourceMap ? 'source-map' : false)
    .output
    .chunkFilename((chunkData) => {
        return chunkData.chunk.name === 'vendor' ? 'js/[name].js': 'js/[id].[contenthash:8].js';
     })

Error:

WebpackOptionsValidationError: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
 - configuration.output.chunkFilename should be a string.
   -> The filename of non-entry chunks as relative path inside the `output.path` directory.

What is the expected behavior?
I would expect the output.chunkFilename to also allow a function if it simply works when you don't specify the option. And use a function within the output.filename property

Other relevant information:
webpack version: 4.29
Node.js version: 8.15.1
Operating System: Ubuntu 18.04.2 LTS

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions