Package Exports
- gulp-nunjucks-render
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (gulp-nunjucks-render) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
gulp-nunjucks-render
Render Nunjucks templates
Issues with the output should be reported on the Nunjucks issue tracker.
Install
Install with npm
npm install --save-dev gulp-nunjucks-renderExample
var gulp = require('gulp');
var nunjucksRender = require('gulp-nunjucks-render');
gulp.task('default', function () {
nunjucksRender.nunjucks.configure(['src/templates/'], {watch: false});
return gulp.src('src/templates/*.html')
.pipe(nunjucksRender())
.pipe(gulp.dest('dist'));
});Note: To keep Nunjucks render from eating up all your ram, make sure to specify your watch path and turn off Nunjucks' internal watcher. nunjucksRender.nunjucks.configure(['src/path/to/templates/'], {watch: false}); This will also allow you to define your paths relatively.
Example with gulp data
var gulp = require('gulp');
var nunjucksRender = require('gulp-nunjucks-render');
var data = require('gulp-data');
function getDataForFile(file){
return {
example: 'data loaded for ' + file.relative
};
}
gulp.task('default', function () {
nunjucksRender.nunjucks.configure(['src/templates/'], {watch: false});
return gulp.src('src/templates/*.html')
.pipe(data(getDataForFile))
.pipe(nunjucksRender())
.pipe(gulp.dest('dist'));
});API
nunjucks-render(context)
Same context as nunjucks.render().
For example
nunjucksRender({css_path: 'http://company.com/css/'});For the following template
<link rel="stylesheet" href="{{ css_path }}test.css" />Would render
<link rel="stylesheet" href="http://company.com/css/test.css" />Watch mode
To prevent Nunjucks internal watch mode during gulp task use watch parameter:
nunjucksRender.nunjucks.configure([ './source' ], { watch: false });License
MIT © Carlos G. Limardo
Shout-outs
Sindre Sorhus who wrote the original gulp-nunjucks for precompiling Nunjucks templates. I updated his to render instead of precompile.
kristijanhusak for bug fixes and help with maintenance.