模板引擎(Views)

模板引擎插件

安装

$ npm install -S @umajs/plugin-views
1

开启

在 plugin.config.ts 中开启 plugin-views 插件

// plugin.config.ts
export default {
    views: {
        options: <viewsOptions>{
            root: './views',
            opts: {
            },
        }
    }
}
1
2
3
4
5
6
7
8
9
10

options.root

模板文件的根路径

options.opts

模板文件插件配置

type TKoaViewsOptions = {
  /*
   * autoRender the result into ctx.body, defaults to true
   */
  autoRender?: boolean,
  /*
   * default extension for your views
   */
  extension?: string,
  /*
   * these options will get passed to the view engine
   */
  options?: any,
  /*
   * map a file extension to an engine
   */
  map?: any,
  /*
   * replace consolidate as default engine source
   */
  engineSource?: any,
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22