nestjs

nestjs框架中使用nunjucks模板引擎

月盾
main.ts import { NestFactory } from '@nestjs/core'; import { ExpressAdapter, NestExpressApplication, } from '@nestjs/platform-express'; import { AppModule } from './app.module'; import nunjucks = require('nunjucks'); import { join } from 'path'; async function bootstrap() { const app = await NestFactory.create<NestExpressApplication>( AppModule, new ExpressAdapter(), ); app.useStaticAssets(join(__dirname, '..', 'public')); // NestFactory.create需要加泛型参数<NestExpressApplication> app.setBaseViewsDir(join(__dirname, '..', 'views')); // 修改模板文件后立马生效,否则需要重启服务,nunjucks watch参数也有相同作用 nunjucks.configure('views', { ext:'njk', autoescape: true, express: app, watch: true, }); await app.listen(3000, () => { }); } bootstrap(); app.