{"id":15018084,"url":"https://github.com/sindresorhus/gulp-nunjucks","last_synced_at":"2025-04-05T08:07:31.789Z","repository":{"id":12851851,"uuid":"15527742","full_name":"sindresorhus/gulp-nunjucks","owner":"sindresorhus","description":"Precompile Nunjucks templates","archived":false,"fork":false,"pushed_at":"2023-12-10T20:45:46.000Z","size":49,"stargazers_count":151,"open_issues_count":8,"forks_count":19,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-03-28T21:30:57.283Z","etag":null,"topics":["gulp-plugin","javascript","nodejs","nunjucks","precompile","template"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sindresorhus.png","metadata":{"funding":{"github":"sindresorhus","open_collective":"sindresorhus","custom":"https://sindresorhus.com/donate"},"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2013-12-30T12:54:03.000Z","updated_at":"2025-01-13T05:58:48.000Z","dependencies_parsed_at":"2023-12-12T20:42:16.780Z","dependency_job_id":"4cd70a63-55ba-4649-960e-9cb0d1167b4d","html_url":"https://github.com/sindresorhus/gulp-nunjucks","commit_stats":{"total_commits":66,"total_committers":13,"mean_commits":5.076923076923077,"dds":"0.18181818181818177","last_synced_commit":"5c0b1466727bebdffab17b7a8f298d2b1c8114ac"},"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fgulp-nunjucks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fgulp-nunjucks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fgulp-nunjucks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fgulp-nunjucks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sindresorhus","download_url":"https://codeload.github.com/sindresorhus/gulp-nunjucks/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247305934,"owners_count":20917208,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gulp-plugin","javascript","nodejs","nunjucks","precompile","template"],"created_at":"2024-09-24T19:51:25.443Z","updated_at":"2025-04-05T08:07:31.766Z","avatar_url":"https://github.com/sindresorhus.png","language":"JavaScript","funding_links":["https://github.com/sponsors/sindresorhus","https://opencollective.com/sindresorhus","https://sindresorhus.com/donate"],"categories":["插件","Plugins"],"sub_categories":["模板","Templating"],"readme":"# gulp-nunjucks\n\n\u003e Compile/precompile [Nunjucks](https://mozilla.github.io/nunjucks/) templates\n\n*Issues with the output should be reported on the Nunjucks [issue tracker](https://github.com/mozilla/nunjucks/issues).*\n\n## Install\n\n```sh\nnpm install --save-dev gulp-nunjucks\n```\n\n## Usage\n\n### Compile\n\n```js\nimport gulp from 'gulp';\nimport {nunjucksCompile} from 'gulp-nunjucks';\n\nexport default () =\u003e (\n\tgulp.src('templates/greeting.html')\n\t\t.pipe(nunjucksCompile({name: 'Sindre'}))\n\t\t.pipe(gulp.dest('dist'))\n);\n```\n\nYou can alternatively use [gulp-data](https://github.com/colynb/gulp-data) to inject the data:\n\n```js\nimport gulp from 'gulp';\nimport {nunjucksCompile} from 'gulp-nunjucks';\nimport data from 'gulp-data';\n\nexport default () =\u003e (\n\tgulp.src('templates/greeting.html')\n\t\t.pipe(data(() =\u003e ({name: 'Sindre'})))\n\t\t.pipe(nunjucksCompile())\n\t\t.pipe(gulp.dest('dist'))\n);\n```\n\n### Precompile\n\n```js\nimport gulp from 'gulp';\nimport {nunjucksPrecompile} from 'gulp-nunjucks';\n\nexport default () =\u003e (\n\tgulp.src('templates/greeting.html')\n\t\t.pipe(nunjucksPrecompile())\n\t\t.pipe(gulp.dest('dist'))\n);\n```\n\n## API\n\n### nunjucksCompile(data?, options?)\n\nCompile a template using the provided `data`.\n\n#### data\n\nType: `object`\n\nThe data object used to populate the text.\n\n#### options\n\nType: `object`\n\nOptions will be passed directly to the Nunjucks [Environment constructor](https://mozilla.github.io/nunjucks/api.html#constructor) which will be used to compile templates.\n\n##### options.env\n\nType: `nunjucks.Environment`\\\nDefault: `new nunjucks.Environment()`\n\nThe custom Nunjucks [Environment object](https://mozilla.github.io/nunjucks/api.html#environment) which will be used to compile templates. If supplied, the rest of `options` will be ignored.\n\n##### options.filters\n\nType: `object`\n\nAn object containing [custom filters](https://mozilla.github.io/nunjucks/api.html#custom-filters) that will be passed to Nunjucks, with the filter's name as key and the filter function as value.\n\nAsync filters should be defined as async functions. You cannot use just a promise-returning function.\n\n```js\n{\n\t'shorten': string =\u003e string.slice(0, 5),\n\t'round': number =\u003e Math.round(number),\n\t'fetch': async url =\u003e {\n\t\tconst response = await fetch(url);\n\t\tconst result = await response.text();\n\t\treturn result;\n\t}\n}\n```\n\n### nunjucksPrecompile(options?)\n\nPrecompile a template for rendering dynamically at a later time.\n\nSame options as [`nunjucks.precompile()`](https://mozilla.github.io/nunjucks/api.html#precompile) except for `name`.\n\n#### options\n\nType: `object`\n\n##### name\n\nType: `Function`\\\nDefault: Relative template path\\\nExample: `templates/list.html`\n\nYou can override the default behavior by supplying a function which gets the current [File](https://github.com/gulpjs/vinyl#options) object and is expected to return the name.\n\nExample:\n\n```js\n{\n\tname: file =\u003e `template-${file.relative}`\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Fgulp-nunjucks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsindresorhus%2Fgulp-nunjucks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Fgulp-nunjucks/lists"}