Rollup plugin to emit files from EJS templates into the bundle output. Version 3.1.0 (stable, last updated 2021). This plugin uses Rollup's emitFile() method, allowing other plugins to process emitted files (e.g., minify HTML). It provides a basic layout system, automatic JavaScript and stylesheet linking via helper variables (javascripts, stylesheets, content), and supports any file type, not just HTML. Key differentiator: unlike rollup-plugin-bundle-html, it enables post-processing of emitted assets. Requires rollup ^2.10.0 as peer dependency. Ships TypeScript definitions.
npm install rollup-plugin-emit-ejsVerified import paths — ran on the pinned version, not inferred.
Basic usage: emit an HTML file from EJS template with layout and data. Shows plugin config in rollup.config.js.
Do not list layout template in exclude option; it is excluded automatically.
Ensure output format supports multiple chunks (e.g., 'es', 'cjs') and that code splitting is enabled.
Either use .ejs only and rely on extension option, or use explicit extensions in filename and omit extension option.
Monitor compatibility with upcoming Rollup releases; consider alternatives if Rollup 4+ is needed.
Install ejs: npm install ejs
Ensure the template file exists and is relative to the src directory (e.g., if src='templates', use layout='templates/layout.html.ejs').
Use ESM import: import emitEJS from 'rollup-plugin-emit-ejs' or use dynamic import: const emitEJS = await import('rollup-plugin-emit-ejs').then(m => m.default).