koa-generator支持nunjucks
koa-generator是和express-generator类似的生成器,主要生成koa 2.x项目骨架
安装
npm i -g koa-generator
创建项目
koa2 -n hellonunjucks
create : hellonunjucks
create : hellonunjucks/package.json
create : hellonunjucks/app.js
create : hellonunjucks/public
create : hellonunjucks/public/javascripts
create : hellonunjucks/public/images
create : hellonunjucks/public/stylesheets
create : hellonunjucks/public/stylesheets/style.css
create : hellonunjucks/routes
create : hellonunjucks/routes/index.js
create : hellonunjucks/routes/users.js
create : hellonunjucks/views
create : hellonunjucks/views/index.nunjucks
create : hellonunjucks/views/layout.nunjucks
create : hellonunjucks/views/error.nunjucks
create : hellonunjucks/bin
create : hellonunjucks/bin/www
install dependencies:
$ cd hellonunjucks && npm install
run the app:
$ DEBUG=hellonunjucks:* npm start
安装依赖
$ cd hellonunjucks
$ npm i
启动
$ npm start
4 回复
koa-views里使用nunjucks还有点别扭的地方,命名layout.nunjucks和index.nunjucks在同一级目录,在extends的时候,还是要使用完整路径写,比较麻烦。。。
$ cat views/index.nunjucks
{% extends 'views/layout.nunjucks' %}
{% block content %}
<h1> {{ title }} </h1>
<p> Welcome to {{ title }} </p>
{% endblock %}
目前在用的是直接封装nunjucks模板的koa-view,不用完整路径
@flynntsc 应该是nunjucks.configure包含了路径
更新了koa-router 7.1.1版本