Skip to content

Commit e3bd763

Browse files
committed
fix: the pathData.chunk.name is undefined when the js.filename is a function
1 parent 926584e commit e3bd763

5 files changed

Lines changed: 13 additions & 5 deletions

File tree

CHANGELOG.md

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

3+
## 3.4.6 (2024-01-02)
4+
5+
fix: the `pathData.chunk.name` is undefined when the `js.filename` is a function, this bug was introduced in `3.4.5`
6+
37
## 3.4.5 (2024-01-01)
48

59
fix: the `pathData.filename` is undefined after changes when the `js.filename` is a function

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "html-bundler-webpack-plugin",
3-
"version": "3.4.5",
3+
"version": "3.4.6",
44
"description": "HTML bundler plugin for webpack handles a template as an entry point, extracts CSS and JS from their sources referenced in HTML, supports template engines like Eta, EJS, Handlebars, Nunjucks.",
55
"keywords": [
66
"html",

src/Plugin/AssetEntry.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ class AssetEntry {
620620
* @private
621621
*/
622622
static #add(entry, assetEntryOptions) {
623-
const { name, filenameTemplate, outputPath } = assetEntryOptions;
623+
const { name, originalName, filenameTemplate, outputPath } = assetEntryOptions;
624624

625625
if (path.isAbsolute(outputPath)) {
626626
assetEntryOptions.publicPath = path.relative(Option.getWebpackOutputPath(), outputPath);
@@ -636,8 +636,10 @@ class AssetEntry {
636636
// clone the pathData object to modify the chunk object w/o side effects in the main compilation
637637
const pathDataCloned = { ...pathData };
638638
pathDataCloned.chunk = { ...pathDataCloned.chunk };
639-
pathDataCloned.chunk.name = assetEntryOptions.originalName;
640-
pathDataCloned.chunk.runtime = assetEntryOptions.originalName;
639+
if (originalName) {
640+
pathDataCloned.chunk.name = originalName;
641+
pathDataCloned.chunk.runtime = originalName;
642+
}
641643

642644
// the `filename` property of the `PathData` type should be a source file, but in entry this property not exists
643645
if (pathDataCloned.filename == null) {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
console.log('>> home 12345678');
1+
console.log('>> home');

test/manual/watch-entry-dir/webpack.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ module.exports = {
2222
filename: (pathData) => {
2323
console.log('-- JS.filename: ', {
2424
filename: pathData.filename,
25+
pathData,
2526
});
2627

2728
return 'js/[name].[contenthash:8].js';
@@ -33,6 +34,7 @@ module.exports = {
3334
filename: (pathData) => {
3435
console.log('-- CSS.filename: ', {
3536
filename: pathData.filename,
37+
pathData,
3638
});
3739

3840
return 'css/[name].[contenthash:8].css';

0 commit comments

Comments
 (0)