gulp-html-partial
Gulp plugin for including HTML files into each other. Made for fun and my personal needs, but I'll appreciate if anyone will use it \( ゚ヮ゚)/
I know, there are some long-time solutions like gulp-file-include, but I wanted to create something on my own with html-like syntax.
Supports nested partials and passing parameters as attributes.
Requirements
- gulp (>=3.9.1) (guess it'll work with older versions too)
- Node (>=6.5.0) (not sure 4.x will handle all ES6 stuff)
Installation
npm install --save-dev gulp-html-partial
Usage
in HTML:
Files are included in src
and dist
directories.
index.html:
_1.html:
@@title Some span Some text
_2.html:
Some text @@param @@dashed-paramSome text
Results in:
Some title Some span Some text Some text Nested partial Some-dashed-param Some text
gulpfile.js
:
in const gulp = ;const htmlPartial = ; gulp;
Options
const defaults = basePath: '' tagName: 'partial' variablePrefix: '@@'
basePath
- base path for your partials, relative togulpfile.js
tagName
- name of your partial tag, must have at leastsrc
attribute with path to partial filevariablePrefix
- prefix of variable keys passed as attributes into partials
Notes
- missing partials defaults to empty string
- errors fire as logs, not as events, to make sure every, not only the first one, missing partial will be described - but I guess there is a way to make that work with events too