@hidoo/gulp-task-build-html-handlebars v0.19.0
@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-handlebars
Usage
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
options
Object options (optional, default{}
)options.name
String task name (use as displayName) (optional, default'build:html'
)options.src
String source pathoptions.dest
String destination pathoptions.extname
String destination extname (optional, default'.html'
)options.partials
String Handlebars partials files glob pattern (optional, default''
)options.layouts
String Handlebars layouts files glob pattern (optional, default''
)options.helpers
String Handlebars helpers files glob pattern (optional, default''
)options.data
String data files glob pattern (optional, default''
)options.compress
(Boolean | Object) compress file whether or not (optional, defaultfalse
)options.compress.htmlmin
Array[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function) htmlmin settings see: gulp-htmlmin options.
options.onFilesParsed
Function[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object) additional process after data files parsed (optional, default(context)=>context
)options.onFrontMatterParsed
Function[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object) additional process after front matter parsed (optional, default(context)=>context
)options.verbose
Boolean 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 test
License
MIT
1 month ago
3 months ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 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
6 years ago
6 years ago