Registry / web-framework / rollup-plugin-generate-html-template

rollup-plugin-generate-html-template

JSON →
library1.7.0jsnpmunverified

Rollup plugin that automatically injects script and link tags for the final bundle into an HTML template. Current stable version is 1.7.0, with a low release cadence (last release in 2020). It simplifies HTML generation by inserting a <script> tag before </body> and a <link> tag before </head> based on the bundle output. Supports CSS injection, custom attributes, and variable replacement. Unlike more complex alternatives like rollup-plugin-html or @rollup/plugin-html, this focuses on template injection with minimal configuration.

npm install rollup-plugin-generate-html-template
INSTALL
IMPORT
SIG · ROLLUP-PLUGIN-GENE
R
rollup-plugin-generate-html-template
web-frameworkjavascriptv1.7.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18223 runs
build_error
glibc
node 18223 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import htmlTemplate from 'rollup-plugin-generate-html-template'
const htmlTemplate = require('rollup-plugin-generate-html-template')
ESM default import; CommonJS require works in Node but not recommended for Rollup configs.
htmlTemplate
import htmlTemplate from 'rollup-plugin-generate-html-template'
import { htmlTemplate } from 'rollup-plugin-generate-html-template'
Named export does not exist; must use default import.
htmlTemplate (with destructured options)
import htmlTemplate from 'rollup-plugin-generate-html-template'; htmlTemplate({ template: 'src/template.html', target: 'dist/index.html' })
import htmlTemplate from 'rollup-plugin-generate-html-template'; htmlTemplate.template({ template: 'src/template.html' })
The function is called directly; there is no static .template method.

Basic Rollup config using the plugin to inject bundle script and link tags into an HTML template.

// rollup.config.js import htmlTemplate from 'rollup-plugin-generate-html-template'; export default { input: 'src/index.js', output: { file: 'dist/bundle.js', format: 'iife', }, plugins: [ htmlTemplate({ template: 'src/template.html', target: 'index.html', }), ], };
Debug
Known issues
breakingVersion 1.0.0 changed the import from a named export to a default export.
fix
Update import from `import { generateHtmlTemplate } from 'rollup-plugin-generate-html-template'` to `import htmlTemplate from 'rollup-plugin-generate-html-template'`.
affects: <1.0.0
breakingVersion 1.2.0 changed the plugin to inject all entry points instead of failing; dynamic imports are not embedded.
fix
If you relied on the plugin failing for multiple entry points, update your configuration to handle multiple script tags.
affects: <1.2.0
deprecatedThe `entry` and `dest` options from Rollup 0.x are not supported; use `input` and `output`.
fix
Use Rollup's `input` and `output` options as shown in the quickstart.
affects: >=0.60.0
gotchaThe plugin does not create the output directory automatically if it does not exist for the target file.
fix
Upgrade to v1.2.0+ or ensure the output directory exists before building.
affects: <1.2.0
gotchaCSS injection only works if the bundle generates a CSS file; the plugin assumes the same base name as the JS bundle.
fix
Ensure your Rollup output includes a CSS file matching the JS bundle name, or configure accordingly.
affects: >=1.7.0
Errors
Common errors & fixes
TypeError: htmlTemplate is not a function
Using a named import instead of default import.
fix
Change to `import htmlTemplate from 'rollup-plugin-generate-html-template'`.
ENOENT: no such file or directory, open ...
The output directory for the target HTML file does not exist.
fix
Create the directory manually or upgrade to v1.2.0+ which auto-creates directories.
Error: Could not resolve entry module
Using old `entry` option instead of `input`.
fix
Replace `entry: 'src/index.js'` with `input: 'src/index.js'`.
Upgrade
Version history
1.7.0latest on npm
Audit
Dependencies
rolluprequiredpeer dependency required; plugin works with rollup >=1.1.2
Agent activity
12 hits · last 30 days
node
8
OpenAI (training)
2
Resources
rollup-plugin-generate-html-template — npm install rollup-plugin-generate-html-template · libregistry