maranda-koa2-nunjucks
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

useage

npm i --save maranda-koa2-nunjucks

for the complete maranda koa server case, with static, session-mysql, koabody, router

please visit https://github.com/yu87109/maranda-koa-server-example

this example is used for ts, if you are js user, if can use as almost the same, just delete the type define.

app.ts

import {NunjucksKoa, Koa, Nunjucks, NunjucksCtx} from 'maranda-koa2-nunjucks';
import {join as pathJoin } from 'path';
 
interface Ctx extends NunjucksCtx{
    //if have other context
}
const app = new NunjucksKoa<any, Ctx>(
    [
        pathJoin(__dirname, '../view1'), 
        pathJoin(__dirname, '../view2')
    ],
    {
        noCache: true
    }
);
//if you do not want use NunjucksKoa, you use as follows:
const app = new Koa<any, Ctx>();
app.context.nunjucks = new Nunjucks.Environment(
    new Nunjucks.FileSystemLoader(pathJoin(__dirname, '../assets/ssr')),
    {
        noCache: true,
    }
);
 
app.use(async (ctx, next)=>{
    ctx.nunjucks.render('a.njk', {...})
}
app.listen(80);

for more Versions, click see the changelog

Package Sidebar

Install

npm i maranda-koa2-nunjucks

Weekly Downloads

1

Version

2.0.0

License

ISC

Unpacked Size

10.9 kB

Total Files

7

Last publish

Collaborators

  • yu87109