gulp-domly
Plugin for gulp 3 to precompile DOMly templates
Usage
Install gulp-domly
as a development dependency:
npm install --save-dev gulp-domly
Compiling to a namespace for the browser
gulp-declare can be used to safely declare template namespaces and make templates available for use in the browser.
First, install development dependencies:
npm install --save-dev gulp-handlebars gulp-declare gulp-concat
Given the following directory structure:
├── gulpfile.js # Your gulpfile
└── source/ # Your application's source files
└── templates/ # Templates named with dot notation
└── app.html # Delcared as MyApp.templates.app
└── app.header.html # Delcared as MyApp.templates.app.header
To compile all templates in source/templates/
to build/js/templates.js
under the MyApp.templates
namespace:
gulpfile.js
var domly = ;var declare = ;var concat = ; gulp;
The template's filename is combined with the namespace, so the resulting build/js/templates.js
would look like:
this"MyApp" = this"MyApp" || {};this"MyApp""templates" = this"MyApp""templates" || {};this"MyApp""templates""app" = { /* compiled */ };this"MyApp""templates""app" = this"MyApp""templates""app" || {};this"MyApp""templates""app""header" = { /* compiled */ };
You can then use your templates:
documentbody;
Compiling to various module systems
See the gulp-define-module
documentation for details on how to define templates as AMD, Node, CommonJS, and hybrid modules.
First, install development dependencies:
npm install --save-dev gulp-handlebars gulp-define-module
To compile all templates in source/templates/
to build/js/templates/
as separate modules:
gulpfile.js
var domly = ;var defineModule = ; gulp;
Passing compiler options
You can pass any compiler options accepted by domly.precompile()
:
gulpfile.js
gulp;
Compiling using a specific DOMly version
You can use different versions of DOMly by specifying the version in your package.json
and passing it as options.domly
:
package.json
gulpfile.js
gulp;
API
domly(options)
options.compilerOptions
Type: Object
Compiler options to pass to domly.precompile()
.
options.domly
Type: Object
DOMly library to use for precompilation. By default, the latest stable version of DOMly is used.