Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
nschipperbrainsmith opened this issue Aug 6, 2019 · 4 comments
Labels

Comments

@nschipperbrainsmith
Copy link

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

@jamesjose03
Copy link
Contributor

@sokra I would like to give it a try. It would be great if you could throw light on the required files to be worked on.

@sokra
Copy link
Member

sokra commented Aug 7, 2019

I think this has already been fixed in webpack 5. webpack 4 can't easily support this because of technical restrictions.

@webpack-bot
Copy link
Contributor

This issue had no activity for at least three months.

It's subject to automatic issue closing if there is no activity in the next 15 days.

@webpack-bot
Copy link
Contributor

Issue was closed because of inactivity.

If you think this is still a valid issue, please file a new issue with additional information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants