Skip to content

Commit b6c1611

Browse files
committed
fix: js.chunkFilename should default to js.filename when possible
1 parent e023d70 commit b6c1611

19 files changed

Lines changed: 156 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## Not Released
4+
5+
- fix: `js.chunkFilename` should default to `js.filename` when possible.
6+
37
## 4.19.0
48

59
### 🔥 BREAKING CHANGES by inlining SVG only

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,5 +216,6 @@
216216
"webpack": "5.96.1",
217217
"webpack-cli": "6.0.1",
218218
"webpack-dev-server": "^5.2.0"
219-
}
219+
},
220+
"packageManager": "pnpm@10.7.0+sha512.6b865ad4b62a1d9842b61d674a393903b871d9244954f652b8842c2b553c72176b278f64c463e52d40fff8aba385c235c8c9ecf5cc7de4fd78b8bb6d49633ab6"
220221
}

src/Plugin/Option.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,19 @@ class Option {
236236

237237
if (js.chunkFilename) {
238238
options.output.chunkFilename = js.chunkFilename;
239-
} else {
239+
} else if (js.filename) {
240+
/**
241+
* When js.filename exists, it is possible that options.output.filename is overridden
242+
*
243+
* But, that overide is happened after webpack populated the options.output.filename, thus
244+
* webpack doesn't see the js.filename, and will populate the options.output.chunkFilename
245+
* with its default value "[id].js". This is not ideal since js.filename should be preferred
246+
* over "[id].js".
247+
*
248+
* So we manually override the options.output.chunkFilename with js.filename
249+
*/
250+
options.output.chunkFilename = js.filename;
251+
} else { // default to options.output.chunkFilename, which webpack always populate with no-exist-default "[id].js"
240252
js.chunkFilename = options.output.chunkFilename;
241253
}
242254

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
h1{color:red}

test/cases/option-js-chunkFilename-default-to-filename/expected/assets/js/473.17e6164c.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/cases/option-js-chunkFilename-default-to-filename/expected/assets/js/803.675bc0d4.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/cases/option-js-chunkFilename-default-to-filename/expected/assets/js/881.e0e6f991.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/cases/option-js-chunkFilename-default-to-filename/expected/assets/js/992.c549a43d.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/cases/option-js-chunkFilename-default-to-filename/expected/assets/js/main.9808bcf2.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/cases/option-js-chunkFilename-default-to-filename/expected/assets/js/runtime.b4aec825.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)