在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):sindresorhus/gulp-nunjucks开源软件地址(OpenSource Url):https://github.com/sindresorhus/gulp-nunjucks开源编程语言(OpenSource Language):JavaScript 100.0%开源软件介绍(OpenSource Introduction):gulp-nunjucks
Issues with the output should be reported on the Nunjucks issue tracker. Install
UsageCompileconst gulp = require('gulp');
const nunjucks = require('gulp-nunjucks');
exports.default = () => (
gulp.src('templates/greeting.html')
.pipe(nunjucks.compile({name: 'Sindre'}))
.pipe(gulp.dest('dist'))
); You can alternatively use gulp-data to inject the data: const gulp = require('gulp');
const nunjucks = require('gulp-nunjucks');
const data = require('gulp-data');
exports.default = () => (
gulp.src('templates/greeting.html')
.pipe(data(() => ({name: 'Sindre'})))
.pipe(nunjucks.compile())
.pipe(gulp.dest('dist'))
); Precompileconst gulp = require('gulp');
const nunjucks = require('gulp-nunjucks');
exports.default = () => (
gulp.src('templates/greeting.html')
.pipe(nunjucks.precompile())
.pipe(gulp.dest('dist'))
); APInunjucks.compile(data?, options?)Compile a template using the provided dataType: The data object used to populate the text. optionsType: Options will be passed directly to the Nunjucks Environment constructor which will be used to compile templates. options.envType: The custom Nunjucks Environment object which will be used to compile templates. If supplied, the rest of options.filtersType: An object containing custom filters that will be passed to Nunjucks, with the filter's name as key and the filter function as value. Async filters should be defined as async functions. You cannot use just a promise-returning function. Example: {
'shorten': string => string.slice(0, 5),
'round': number => Math.round(number),
'fetch': async url => {
const response = await fetch(url);
const result = await response.text();
return result;
}
} nunjucks.precompile(options?)Precompile a template for rendering dynamically at a later time. Same options as optionsType: nameType: You can override the default behavior by supplying a function which gets the current File object and is expected to return the name. Example: {
name: file => `template-${file.relative}`
} |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论