Skip to content

fix(bug): chunkFilename as function doesn't work#6672

Merged
sokra merged 3 commits intowebpack:masterfrom
EugeneHlushko:fix/6639
Mar 29, 2018
Merged

fix(bug): chunkFilename as function doesn't work#6672
sokra merged 3 commits intowebpack:masterfrom
EugeneHlushko:fix/6639

Conversation

@EugeneHlushko
Copy link
Copy Markdown
Member

@EugeneHlushko EugeneHlushko commented Mar 5, 2018

What kind of change does this PR introduce?
Fixes #6639

Did you add tests for your changes?
no

If relevant, link to documentation update:

Summary
For technically reasons chunkFilename can't be a function. This PR disabling it on the the schema level.

Does this PR introduce a breaking change?
no

Other information

@EugeneHlushko
Copy link
Copy Markdown
Member Author

Congrats on PR privileges 🍾 @ooflorent

@webpack-bot
Copy link
Copy Markdown
Contributor

Thank you for your pull request! The most important CI builds succeeded, we’ll review the pull request soon.

Copy link
Copy Markdown
Member

@sokra sokra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is some code in WebpackOptionsDefaulter which sets the default of chunkFilename to a function when filename is a function. Add an Error (thrown) in this case too.

@EugeneHlushko
Copy link
Copy Markdown
Member Author

EugeneHlushko commented Mar 6, 2018

Hmm not sure i follow, if it throws here:

if (typeof filename === "function") return filename;

means tests will fail for providing output.filename as a function in /tests/configCases/output/function.
Maybe stop defaulting to a function instead?

@sokra can you clarify?

@sokra
Copy link
Copy Markdown
Member

sokra commented Mar 6, 2018

@EugeneHlushko ok you are right. We can just stop defaulting it to a function.

You can skip the following lines when filename is a function:

const hasName = filename.includes("[name]");
const hasId = filename.includes("[id]");
const hasChunkHash = filename.includes("[chunkhash]");
// Anything changing depending on chunk is fine
if (hasChunkHash || hasName || hasId) return filename;

@webpack-bot
Copy link
Copy Markdown
Contributor

@EugeneHlushko Thanks for your update.

I labeled the Pull Request so reviewers will review it again.

@sokra Please review the new changes.

@EugeneHlushko
Copy link
Copy Markdown
Member Author

So i had to wrap 1 more line into the if statement

filename.replace(/(^|\/)([^/]*(?:\?|$))/, "$1[id].$2");

if (hasChunkHash || hasName || hasId) return filename;
// Elsewise prefix "[id]." in front of the basename to make it changing
return filename.replace(/(^|\/)([^/]*(?:\?|$))/, "$1[id].$2");
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to return something in the case of filename being a function too.

Maybe just return [id].js

@EugeneHlushko
Copy link
Copy Markdown
Member Author

yeap looks good now

@sokra sokra merged commit b30de38 into webpack:master Mar 29, 2018
@sokra
Copy link
Copy Markdown
Member

sokra commented Mar 29, 2018

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

chunkFilename - function doesn't work - Webpack 4

4 participants