jantimon / jantimon/html-webpack-plugin

Writing Your Own Templates section does not work

Open
#1,826 3 comments 0 reactions 0 assignees View on GitHub
wontfix
Dominant language
JavaScript
Stars
10.7k
Forks
1.3k
Avg merge
1m
Merged PRs (30d)
1

Description

## Current behaviour πŸ’£

I am trying to use the `templateParameters` to pass some variables into my template and it does not work.
I have followed the examples shown:
- Here: https://github.com/jantimon/html-webpack-plugin#writing-your-own-templates
- And here: https://github.com/jantimon/html-webpack-plugin/tree/main/examples/template-parameters

## Expected behaviour β˜€οΈ

I would like my `<%= title %>` to be replaced with the actual value of my `templateParameters.title` value, i.e. value located inside `locales/de-DE.json` or `locales/en-GB.json`.
I've also tried to modify the `<%= title %>` to `<%= htmlWebpackPlugin.options.templateParameters.title %>`.

### Reproduction Example πŸ‘Ύ

I have created a small repository to reproduce this issue here: https://github.com/einazare/html-webpack-plugin-18n-generator
You will need to:
1. Install the dependencies with `npm install`
2. Build the application with `npm run build`
3. Open `dist/index.html`
4. You will see `<%= title %>` was not replaced by `Some title written in English (Great Britain)`

## Environment πŸ–₯

All the versions from my `package.json` file here:
```
"dependencies": {
"copy-webpack-plugin": "11.0.0",
"html-webpack-plugin": "5.5.0",
"webpack": "5.88.2",
"webpack-cli": "4.9.2",
"webpack-dev-server": "4.8.1"
},
"devDependencies": {
"css-loader": "6.7.1",
"html-loader": "4.2.0",
"style-loader": "3.3.1"
}
```

Also, the output of the above commands here:
```
node -e "var os=require('os');console.log('Node.js ' + process.version + '\n' + os.platform() + ' ' + os.release())"
Node.js v18.16.0
darwin 22.6.0
```

```
npm --version
9.5.1
```

```
npm ls webpack
html-webpack-plugin-18n-generator@1.0.0 /Users/einazare/Desktop/html-webpack-plugin-18n-generator
β”œβ”€β”¬ copy-webpack-plugin@11.0.0
β”‚ └── webpack@5.88.2 deduped
β”œβ”€β”¬ css-loader@6.7.1
β”‚ └── webpack@5.88.2 deduped
β”œβ”€β”¬ html-loader@4.2.0
β”‚ └── webpack@5.88.2 deduped
β”œβ”€β”¬ html-webpack-plugin@5.5.0
β”‚ └── webpack@5.88.2 deduped
β”œβ”€β”¬ style-loader@3.3.1
β”‚ └── webpack@5.88.2 deduped
β”œβ”€β”¬ webpack-cli@4.9.2
β”‚ β”œβ”€β”¬ @webpack-cli/configtest@1.2.0
β”‚ β”‚ └── webpack@5.88.2 deduped
β”‚ └── webpack@5.88.2 deduped
β”œβ”€β”¬ webpack-dev-server@4.8.1
β”‚ β”œβ”€β”¬ webpack-dev-middleware@5.3.3
β”‚ β”‚ └── webpack@5.88.2 deduped
β”‚ └── webpack@5.88.2 deduped
└─┬ webpack@5.88.2
└─┬ terser-webpack-plugin@5.3.9
└── webpack@5.88.2 deduped
```

```
npm ls html-webpack-plugin
html-webpack-plugin-18n-generator@1.0.0 /Users/einazare/Desktop/html-webpack-plugin-18n-generator
└── html-webpack-plugin@5.5.0
```

Thank you πŸ™

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the linked reproduction repository, install its dependencies with npm install, and run npm run build. Read package.json and the locale files at locales/de-DE.json and locales/en-GB.json, then inspect the generated dist/index.html. Done means the template renders the expected title instead of the literal <%= title %> text.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, webpack
Domain
build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.