@hidoo/gulp-task-build-html-handlebars v1.0.0-alpha.4
@hidoo/gulp-task-build-html-handlebars
Task that build html by handlebars for gulp.
Installation
$ npm install --save-dev gulp@next @hidoo/gulp-task-build-html-handlebarsUsage
import { task } from 'gulp';
import buildHtml from '@hidoo/gulp-task-build-html-handlebars';
task(
'html',
buildHtml({
src: '/path/to/html/*.hbs',
dest: '/path/to/dest'
})
);API
buildHtml
return html build task by handlebars
Parameters
optionsObject options (optional, default{})options.nameString task name (use as displayName) (optional, default'build:html')options.srcString source pathoptions.destString destination pathoptions.extnameString destination extname (optional, default'.html')options.partialsString Handlebars partials files glob pattern (optional, default'')options.layoutsString Handlebars layouts files glob pattern (optional, default'')options.helpersString Handlebars helpers files glob pattern (optional, default'')options.dataString data files glob pattern (optional, default'')options.compress(Boolean | Object) compress file whether or not (optional, defaultfalse)options.compress.htmlminArray[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function) htmlmin settings see: gulp-htmlmin options.
options.onFilesParsedFunction[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object) additional process after data files parsed (optional, default(context)=>context)options.onFrontMatterParsedFunction[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object) additional process after front matter parsed (optional, default(context)=>context)options.verboseBoolean out log or not (optional, defaultfalse)
Examples
import { task } from 'gulp';
import buildHtml from '@hidoo/gulp-task-build-html-handlebars';
task(
'html',
buildHtml({
name: 'html:main',
src: '/path/to/html/*.hbs',
dest: '/path/to/dest',
extname: '.php',
partials: '/path/to/html/partials/*.hbs',
layouts: '/path/to/html/layouts/*.hbs',
helpers: '/path/to/html/helpers/*.js',
data: '/path/to/html/data/*.{json,yaml}',
compress: {
htmlmin: {
caseSensitive: true,
collapseWhitespace: true,
conservativeCollapse: true,
preserveLineBreaks: true,
ignoreCustomFragments: [
// php start end tags
/<\?[\s\S]*?\?>/,
// cms tags
/<\/?mt:?[\s\S]*?>/i,
/<\$mt:?[\s\S]*?\$>/i
]
}
},
onFilesParsed: (context) => context,
onFrontMatterParsed: (context) => context,
verbose: false
})
);Returns Function[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)
Template API
Builtin Helpers
See @hidoo/handlebars-helpers.
Template context
global:
| name | example | description |
|---|---|---|
| NODE_ENV | {{#is NODE_ENV 'production'}}...{{/is}} | string of process.env.NODE_ENV |
| compress | {{#if compress}}...{{/if}} | value of options.compress |
| pages | {{#each pages}}...{{/each}} | array of Front Matter for all pages |
path (when file is subdir/index.hbs):
| name | example | description |
|---|---|---|
| path.depth | {{path.depth}} => ../ | depth of file from options.src |
| path.relative | {{path.relative}} => subdir/index.html | relative path of file from options.src |
| path.basename | {{path.basename}} => index.html | basename of file |
| path.extname | {{path.extname}} => .html | extname of file |
Test
$ pnpm testLicense
MIT
5 months ago
6 months ago
7 months ago
2 years ago
2 years ago
4 years ago
5 years ago
5 years ago
5 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago