apedyashev / gulp-template-compile-commonjs

Precompile Lodash templates with Gulp

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

gulp-template-compile-commonjs

Compile Lo-Dash templates (should work with Underscore templates too). Allows to require templates

Synopsis

This plugin isModified version of gulp-template-compile plugin, that allows to require templates in commonjs style.

Install

Plugin is not on npm yet, but you can install it using npm

  npm i https://github.com/apedyashev/gulp-template-compile-commonjs.git#0.0.3--save-dev

Example

gulpfile.js

var gulp = require('gulp');
var template = require('gulp-template-compile-commonjs');
var concat = require('gulp-concat');

gulp.task('default', function () {
	gulp.src('src/*.html')
		.pipe(template())
		.pipe(concat('templates.js'))
		.pipe(gulp.dest('dist'));
});

API

See the Lo-Dash _.template docs.

template(options)

options

Type: Object

options.name

Type: Function Default: Relative template path. Example: templates/list.html

You can override the default behavior by supplying a function which gets the current File object and is expected to return the name.

Example:

{
	name: function (file) {
		return 'tpl-' + file.relative;
	}
}

options.namespace

Type: String Default: 'JST'

The namespace in which the precompiled templates will be assigned. Starting from version 1.0 you could also provide a dotted namespace that will be correctly handled, thanks to fhawkes. For example 'custom.namespace' will result in window['custom']['namespace'].

options.templateSettings

Type: Object Default: null

Lo-Dash _.template options.

License

MIT © Emanuele Ingrosso

About

Precompile Lodash templates with Gulp


Languages

Language:JavaScript 100.0%