egg-view-static
A simple egg view plugin, allow you to render static html from app/public
.
Install
$ npm i egg-view-static --save
Usage
// {app_root}/config/plugin.jsexportsviewStatic = enable: true package: 'egg-view-static';
Set mapping in config
// {app_root}/config/config.default.jsexportsview = defaultViewEngine: 'static' mapping: '.html': 'static' ;
Render in controller
// {app_root}/app/controller/home.js async { // app/static/index.html await thisctx; }
Use replaceFn
to custom render with locals, see test/fixtures/apps/locals/config/config.default.js for more detail.
// {app_root}/config/config.default.jsconfigviewStatic = { return tpl; }; // {app_root}/app/controller/home.js async { // app/static/index.html await thisctx; }
Configuration
// {app_root}/config/config.default.jsexportsviewStatic = // cache: true, // replaceFn: (tpl, locals, options) => tpl,;
- {Boolean}
cache
- whether cache file, default totrue
exceptlocal
mode. It will share cache withegg-static
LRU cache. - {Function}
replaceFn
- custom render replacement, args =(tpl, locals, options)
see config/config.default.js for more detail.
Example
Questions & Suggestions
Please open an issue here.