Registry / devops / rollup-plugin-templatejs

rollup-plugin-templatejs

JSON →
library3.1.4jsnpmunverified

Rollup plugin for template.js, a lightweight JavaScript template engine. Version 3.1.4 requires @templatejs/runtime as a peer dependency. Supports both Rollup and Vite with the same configuration, allowing custom delimiters and sandbox mode. Includes TypeScript types. Active maintenance.

npm install rollup-plugin-templatejs
INSTALL
IMPORT
SIG · ROLLUP-PLUGIN-TEMP
R
rollup-plugin-templatejs
devopsjavascriptv3.1.4
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

default import (function)
import template from 'rollup-plugin-templatejs'
const template = require('rollup-plugin-templatejs').default
ESM default export; wrong only if using require or destructuring incorrectly.
Rollup config usage
// rollup.config.js export default { plugins: [template(options)] }
module.exports = { plugins: [template(options)] } // works for CJS but ESM is preferred
CJS require works but ESM is recommended for modern projects.
TypeScript usage
import type { Options } from 'rollup-plugin-templatejs' import template from 'rollup-plugin-templatejs'
import template from 'rollup-plugin-templatejs' // missing type import for Options
Plugin ships types; use type import for configuration types.

Rollup config using the plugin with custom delimiters, importing a .tmpl file and rendering it.

// rollup.config.js import template from 'rollup-plugin-templatejs'; export default { input: 'src/index.js', output: { file: 'dist/bundle.js', format: 'iife' }, plugins: [ template({ sTag: '<#', eTag: '#>', sandbox: false, include: ['**/*.tmpl'], exclude: 'node_modules/**', }), ], }; // src/index.js import tpl from './demo.tmpl'; document.getElementById('root').innerHTML = tpl({ name: 'World' }); // src/demo.tmpl <div><#=name#></div>
Debug
Known issues
gotchaPlugin must be placed with enforce: 'pre' when used with Vite to ensure it transforms template files before other plugins.
fix
Wrap plugin in an object with enforce: 'pre' in the plugin array, e.g., { ...template(options), enforce: 'pre' }.
affects: >=3.0.0
gotchaThe @templatejs/runtime peer dependency must be installed separately; it is not included automatically.
fix
Run npm install --save @templatejs/runtime alongside the plugin.
affects: >=3.0.0
gotchaChanges in delimiters (sTag/eTag) must match between runtime and plugin configuration; mismatches cause undefined behavior.
fix
Ensure the same sTag and eTag values are used in both template() options and any runtime configuration.
affects: >=3.0.0
deprecatedOlder versions below 3.0.0 used a different API and are no longer supported.
fix
Upgrade to version 3.x and update configuration as per documentation.
affects: <3.0.0
gotchaThe include and exclude options default to ['**/*.tmpl'] and 'node_modules/**' respectively; other file extensions are not processed.
fix
If using .html or other extensions, update the include pattern accordingly.
affects: >=3.0.0
Errors
Common errors & fixes
Cannot find module '@templatejs/runtime'
Runtime peer dependency not installed.
fix
npm install --save @templatejs/runtime
Transform failed with error: template is not a function
Incorrect import style (importing default instead of named) or older version.
fix
Use import template from 'rollup-plugin-templatejs' (ESM default).
Plugin order issue: template files not transformed
Vite enforces plugin order; plugin not set with enforce: 'pre'.
fix
Add enforce: 'pre' to the plugin object.
Type error: Argument of type 'typeof import("...")' is not assignable to parameter
Using CommonJS require in TypeScript without esModuleInterop.
fix
Use ESM import or enable esModuleInterop in tsconfig.json.
Parse error: Unexpected token <
File not matched by include pattern (e.g., .html instead of .tmpl).
fix
Update include to match your file extension (e.g., include: ['**/*.html']).
Upgrade
Version history
3.1.4latest on npm
Audit
Dependencies
@templatejs/runtimerequiredRequired at runtime to execute compiled templates
Agent activity
2 hits · last 30 days
node
2
Resources
rollup-plugin-templatejs — npm install rollup-plugin-templatejs · libregistry