Skip to content

xuxinhang/snowpack-plugin-ejs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

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.

{
  plugins: [
    ['snowpack-plugin-ejs'],
  ],
}

// or...  assign render data
{
  plugins: [
    ['snowpack-plugin-ejs', {
      renderData: {
        nickname: 'Calf',
      },
    }],
  ],
}

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.

let ejs = require('ejs'),
ejs.cache = require('lru-cache')(100);

module.exports = {
  plugins: [
    ['snowpack', { ejsModule: ejs }],
  ],
};

renderOptions

Object | Function: optional

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

{  
  renderOptions: { rmWhitespace: true },
}

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.

{  
  renderOptions: ({ filePath }) => ({
    delimiter: filePath.includes('.obs.ejs') ? '?' : undefined,
  }),
}

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.

{
  renderData: { nickname: 'Calf' },
}

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.

About

Add the support for EJS template engine to Snowpack.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published