1、安装依赖

  1. cnpm i egg-view-arttemplate -S

2、配置config/plugin.js

  1. /** @type Egg.EggPlugin */
  2. module.exports = {
  3. // had enabled by egg
  4. arttemplate:{
  5. enable: true,
  6. package: 'egg-view-arttemplate',
  7. }
  8. };

3、配置config/config.default.js

  1. config.view = {
  2. mapping: {
  3. '.html': 'arttemplate',
  4. },
  5. };
  6. config.arttemplate = {
  7. escape: true,
  8. debug: false,
  9. bail: true,
  10. cache: true
  11. };

4、在app下新建一个view的文件夹

  1. view文件夹里放置.html文件

5、在controller中使用render

  1. const Controller = require('egg').Controller;
  2. class HomeController extends Controller {
  3. async index() {
  4. const { ctx } = this;
  5. await ctx.render("home")
  6. }
  7. }
  8. module.exports = HomeController;