gulp-html2string
v0.1.1
Published
Converts static HTML templates to JavaScript strings.
Downloads
8
Maintainers
Readme
gulp-html2string
A Gulp plugin that converts static HTML templates to JavaScript strings.
Code derived from gulp-html2js.
Installation
npm install gulp-html2string
Usage
In your project's gulpfile.js, create the following task:
var html2string = require('gulp-html2string');
gulp.task('html2js', function () {
return gulp.src('html/*.html')
.pipe(html2string({
base: path.join(__dirname, 'html'), //The base path of HTML templates
createObj: true, // Indicate wether to define the global object that stores
// the global template strings
objName: 'TEMPLATES' // Name of the global template store variable
//say the converted string for myTemplate.html will be saved to TEMPLATE['myTemplate.html']
}))
.pipe(rename({extname: '.js'}))
.pipe(gulp.dest('templates/')); //Output folder
});
Then run
gulp html2js
and your converted JS files will be saved under ./templates/.
Tests
Run
npm run test
See /test/test.js for an example usage.