2.0.0 • Published 5 years ago

maranda-koa2-nunjucks v2.0.0

Weekly downloads
2
License
ISC
Repository
github
Last release
5 years ago

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

2.0.0

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago