Registry / devops / rollup-plugin-ejs

rollup-plugin-ejs

JSON →
library4.0.1jsnpmunverified

A Rollup plugin that loads .ejs (Embedded JavaScript) template files, either returning a compiled render function or rendering to HTML at build time. Current stable version is 4.0.1. Supports file inclusion, SCSS compilation via a linked sass peer dependency, HTML minification via html-minifier, and CSS inlining via the inlineStyles option. The plugin dynamically imports peer dependencies, requiring Node 13.2.0+ when bundling in es format. It is a focused EJS integration for Rollup with no major alternatives in the npm ecosystem.

npm install rollup-plugin-ejs
INSTALL
IMPORT
SIG · ROLLUP-PLUGIN-EJS
R
rollup-plugin-ejs
devopsjavascriptv4.0.1
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 ejs from 'rollup-plugin-ejs'
✗ const ejs = require('rollup-plugin-ejs')
ESM-only; require() may not work depending on the bundler and Node version.
default
✓ import ejs from 'rollup-plugin-ejs'
✗ import { ejs } from 'rollup-plugin-ejs'
The plugin exports a single default function; named import 'ejs' is incorrect.
EjsOptions
✓ import type { EjsOptions } from 'rollup-plugin-ejs'
TypeScript users can import the EjsOptions type for configuration; only works with TypeScript 3.8+ and esModuleInterop.

Rollup configuration using rollup-plugin-ejs with compiler options, render data, and inline styles enabled.

import { rollup } from 'rollup'; import ejs from 'rollup-plugin-ejs'; rollup({ input: 'main.js', plugins: [ ejs({ include: ['**/*.ejs', '**/*.html'], exclude: ['**/index.html'], compilerOptions: { client: true }, render: { data: { title: 'Hello' }, minifierOptions: { removeComments: true } }, inlineStyles: true }) ] }).then(bundle => bundle.write({ dir: 'dist', format: 'es' }));
Debug
Known issues
breakingIn v4, sass and html-minifier are moved to peerDependencies and must be installed manually if needed.
fix
Install relevant peer dependencies: npm install sass html-minifier --save-dev
affects: >=4.0.0
breakingIn v4, the loadStyles option is renamed to inlineStyles.
fix
Update your configuration: replace loadStyles: true with inlineStyles: true
affects: >=4.0.0
deprecatedThe plugin uses dynamic import() for peer dependencies, which requires Node 13.2.0+ when bundling in es format.
fix
Ensure your Node.js version is >=13.2.0 or switch to a different format like cjs.
affects: >=4.0.0
gotchaIf inlineStyles is enabled, the plugin will attempt to compile .scss files via the sass peer dependency; failure to install sass will cause an error.
fix
Install sass as a dev dependency: npm install sass --save-dev
affects: >=4.0.0
gotchaThe plugin expects ejs templates to use the 'locals' variable for data by default; not using it can lead to runtime errors.
fix
Access data via <%= locals.dataKey %> in your ejs templates.
affects: *
Errors
Common errors & fixes
Error: Cannot find module 'sass'
The inlineStyles option is enabled but sass peer dependency is not installed.
fix
Install sass: npm install sass --save-dev
Error: Cannot find module 'html-minifier'
The render.minifierOptions option is used but html-minifier peer dependency is not installed.
fix
Install html-minifier: npm install html-minifier --save-dev
TypeError: ejs is not a function
Using named import { ejs } instead of default import ejs.
fix
Use default import: import ejs from 'rollup-plugin-ejs'
Upgrade
Version history
4.0.1latest on npm
Audit
Dependencies
html-minifieroptionalOptional peer dependency for HTML minification via the render.minifierOptions option.
sassoptionalOptional peer dependency for compiling .scss files when inlineStyles is enabled.
Agent activity
4 hits · last 30 days
node
4
Resources
rollup-plugin-ejs — npm install rollup-plugin-ejs · libregistry