1. 安装
npm i egg-view-ejs --save
2. 找到 项目中的 config/plugin.js 文件
'use strict';
/** @type Egg.EggPlugin */
module.exports = {
// had enabled by egg
// static: {
// enable: true,
// }
//ejs
ejs:{
enable:true,
package:'egg-view-ejs'
}
};
3. 找到 config/config.default.js文件
/* eslint valid-jsdoc: "off" */
'use strict';
/**
* @param {Egg.EggAppInfo} appInfo app info
*/
module.exports = appInfo => {
/**
* built-in config
* @type {Egg.EggAppConfig}
**/
const config = {};
// use for cookie sign key, should change to your own and keep security
config.keys = appInfo.name + '_1552721642040_2181';
// add your middleware config here
config.middleware = [];
// add your user config here
const userConfig = {
// myAppName: 'egg',
};
//配置 ejs 模板引擎
config.view={
mapping:{
'.html':'ejs'
}
};
return {
...config,
...userConfig,
};
};
配置好之后就可以使用了