[go: up one dir, main page]

Skip to content

rspack-contrib/rsbuild-plugin-ejs

Repository files navigation

rsbuild-plugin-ejs

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

npm version license

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.

  • Type: import('ejs').Options
  • Default:
const defaultOptions = {
  filename,
};
  • Example:
pluginEjs({
  ejsOptions: {
    delimiter: "|",
  },
});

License

MIT.