Skip to content

Commit

Permalink
fix: the pathData.chunk.name is undefined when the js.filename is…
Browse files Browse the repository at this point in the history
… a function
  • Loading branch information
webdiscus committed Jan 2, 2024
1 parent 926584e commit d2daffa
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
8 changes: 6 additions & 2 deletions src/Plugin/AssetEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion test/manual/watch-entry-dir/src/views/main.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
console.log('>> home 12345678');
console.log('>> home');
2 changes: 2 additions & 0 deletions test/manual/watch-entry-dir/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module.exports = {
filename: (pathData) => {
console.log('-- JS.filename: ', {
filename: pathData.filename,
pathData,
});

return 'js/[name].[contenthash:8].js';
Expand All @@ -33,6 +34,7 @@ module.exports = {
filename: (pathData) => {
console.log('-- CSS.filename: ', {
filename: pathData.filename,
pathData,
});

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

0 comments on commit d2daffa

Please sign in to comment.