A Gulp plugin that converts static HTML templates to JavaScript strings.
Code derived from gulp-html2js.
npm install gulp-html2string
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/.
Run
npm run test
See /test/test.js for an example usage.