diff --git a/CHANGELOG.md b/CHANGELOG.md index 39d0e26a..534b500a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Change log +## 3.4.6 (2024-01-02) + +fix: the `pathData.chunk.name` is undefined when the `js.filename` is a function, this bug was introduced in `3.4.5` + ## 3.4.5 (2024-01-01) fix: the `pathData.filename` is undefined after changes when the `js.filename` is a function diff --git a/package.json b/package.json index 41352e50..455616a0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "html-bundler-webpack-plugin", - "version": "3.4.5", + "version": "3.4.6", "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.", "keywords": [ "html", diff --git a/src/Plugin/AssetEntry.js b/src/Plugin/AssetEntry.js index aeeff636..227cf594 100644 --- a/src/Plugin/AssetEntry.js +++ b/src/Plugin/AssetEntry.js @@ -635,9 +635,13 @@ class AssetEntry { if (isFunction(filenameTemplate)) { // clone the pathData object to modify the chunk object w/o side effects in the main compilation const pathDataCloned = { ...pathData }; + const { originalName } = assetEntryOptions; + pathDataCloned.chunk = { ...pathDataCloned.chunk }; - pathDataCloned.chunk.name = assetEntryOptions.originalName; - pathDataCloned.chunk.runtime = assetEntryOptions.originalName; + if (originalName) { + pathDataCloned.chunk.name = originalName; + pathDataCloned.chunk.runtime = originalName; + } // the `filename` property of the `PathData` type should be a source file, but in entry this property not exists if (pathDataCloned.filename == null) { diff --git a/test/manual/watch-entry-dir/src/views/main.js b/test/manual/watch-entry-dir/src/views/main.js index ea2fe1a1..c48722e8 100644 --- a/test/manual/watch-entry-dir/src/views/main.js +++ b/test/manual/watch-entry-dir/src/views/main.js @@ -1 +1 @@ -console.log('>> home 12345678'); +console.log('>> home'); diff --git a/test/manual/watch-entry-dir/webpack.config.js b/test/manual/watch-entry-dir/webpack.config.js index 0538f05b..b24c9885 100644 --- a/test/manual/watch-entry-dir/webpack.config.js +++ b/test/manual/watch-entry-dir/webpack.config.js @@ -22,6 +22,7 @@ module.exports = { filename: (pathData) => { console.log('-- JS.filename: ', { filename: pathData.filename, + pathData, }); return 'js/[name].[contenthash:8].js'; @@ -33,6 +34,7 @@ module.exports = { filename: (pathData) => { console.log('-- CSS.filename: ', { filename: pathData.filename, + pathData, }); return 'css/[name].[contenthash:8].css';