项目作者: xuxinhang

项目描述 :
Add support for the EJS template engine to Snowpack.
高级语言: EJS
项目地址: git://github.com/xuxinhang/snowpack-plugin-ejs.git
创建时间: 2021-03-07T14:48:25Z
项目社区:https://github.com/xuxinhang/snowpack-plugin-ejs

开源协议:MIT License

下载


snowpack-plugin-ejs

Bring the power of EJS to Snowpack.


Quick Start

This plugin adds support for the EJS template engine to Snowpack.

Use npm to install it first.

  1. npm i -D snowpack-plugin-ejs

Modify your snowpack config file to enable snowpack-plugin-ejs. You can also add plugin options if you want.

  1. {
  2. plugins: [
  3. ['snowpack-plugin-ejs'],
  4. ],
  5. }
  6. // or... assign render data
  7. {
  8. plugins: [
  9. ['snowpack-plugin-ejs', {
  10. renderData: {
  11. nickname: 'Calf',
  12. },
  13. }],
  14. ],
  15. }

Example

There is an example about how to use snowpack-plugin-ejs in ./example directory.

Plugin Options

ejsModule

optional

Assign this option to use your own ejs module.

This option would be useful when you have to rewrite some members of ejs module.

  1. let ejs = require('ejs'),
  2. ejs.cache = require('lru-cache')(100);
  3. module.exports = {
  4. plugins: [
  5. ['snowpack', { ejsModule: ejs }],
  6. ],
  7. };

renderOptions

Object | Function: optional

Provide options which EJS renderer uses. See EJS’s document for all acceptable items.

  1. {
  2. renderOptions: { rmWhitespace: true },
  3. }

A function can also be provided, whose first argument is same to that of Snowpack’s load hook. This function should return the actually option value.

  1. {
  2. renderOptions: ({ filePath }) => ({
  3. delimiter: filePath.includes('.obs.ejs') ? '?' : undefined,
  4. }),
  5. }

renderData

Object | Function: optional

Assign data to render templates. The data will only be passed to the root template, that is, the data cannot inject into the included templates.

  1. {
  2. renderData: { nickname: 'Calf' },
  3. }

A function can also be provided, whose first argument is same to that of Snowpack’s load hook. This function should return the actually option value.