rollup-plugin-template
raw JSON → 1.0.10 verified Mon Apr 27 auth: no javascript
A Rollup plugin that allows importing HTML files as template strings. Version 1.0.10 is the latest stable release; the package has not seen updates since 2018. It differentiates from other HTML handling plugins by focusing purely on importing raw HTML content without transformation, for use in templating engines or string manipulation. Suitable for projects that need to embed HTML templates directly into JavaScript bundles. No active maintenance or known issues.
Common errors
error Error: Cannot find module 'rollup-plugin-template' ↓
cause The package is not installed or not listed in devDependencies.
fix
Run 'npm install --save-dev rollup-plugin-template' to install it.
error TypeError: template is not a function ↓
cause Using named import instead of default import.
fix
Change import to: import template from 'rollup-plugin-template'
error (!) Plugin template: TypeError: options.include is not a string ↓
cause Passing an array to the include option.
fix
Change include option to a single glob string, e.g., 'src/templates/*.html'
Warnings
gotcha The plugin does not transform HTML in any way; it simply returns the file content as a string. If you need minification or partial injection, use other plugins. ↓
fix Ensure your HTML files are minified before import or use an additional plugin like rollup-plugin-html-minifier.
deprecated The 'include' option is a single string glob, not an array. Passing an array will cause the plugin to fail silently. ↓
fix Use a single string glob for include; for multiple patterns, use a brace expansion or combine with rollup's plugin array.
Install
npm install rollup-plugin-template yarn add rollup-plugin-template pnpm add rollup-plugin-template Imports
- default wrong
import { template } from 'rollup-plugin-template'correctimport template from 'rollup-plugin-template' - template wrong
const template = require('rollup-plugin-template')correctimport template from 'rollup-plugin-template' - template(options) wrong
template({ include: ['*.html'] })correcttemplate({ include: '*.html' })
Quickstart
// rollup.config.js
import template from 'rollup-plugin-template';
export default {
input: 'src/index.js',
output: {
file: 'dist/bundle.js',
format: 'iife'
},
plugins: [
template({
include: 'src/templates/**/*.html'
})
]
};