Home

Awesome

rsbuild-plugin-ejs

An Rsbuild plugin to provide support for the EJS template engine.

<p> <a href="https://npmjs.com/package/rsbuild-plugin-ejs"> <img src="https://img.shields.io/npm/v/rsbuild-plugin-ejs?style=flat-square&colorA=564341&colorB=EDED91" alt="npm version" /> </a> <img src="https://img.shields.io/badge/License-MIT-blue.svg?style=flat-square&colorA=564341&colorB=EDED91" alt="license" /> </p>

Usage

Install:

npm add rsbuild-plugin-ejs -D

Add plugin to your rsbuild.config.ts:

// rsbuild.config.ts
import { pluginEjs } from "rsbuild-plugin-ejs";

export default {
  plugins: [pluginEjs()],
};

Using EJS Templates

After the plugin registration is completed, Rsbuild will automatically parse template files with the .ejs extension and compile them using the EJS template engine.

For example, first create a src/index.ejs file, and point to that file using html.template:

export default {
  html: {
    template: "./src/index.ejs",
  },
};

Then, you can use EJS syntax in the index.ejs template:

<!-- Input -->
Hello <%= foo %>!

<!-- Output -->
Hello Rsbuild!

Refer to the EJS documentation for more details.

Options

ejsOptions

Used to set the compilation options for EJS. For detailed options, please refer to the EJS API Reference.

const defaultOptions = {
  filename,
};
pluginEjs({
  ejsOptions: {
    delimiter: "|",
  },
});

License

MIT.