gulp-html2string-1

0.1.2 • Public • Published

gulp-html2string

Build Status

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.

Package Sidebar

Install

npm i gulp-html2string-1

Weekly Downloads

2

Version

0.1.2

License

MIT

Last publish

Collaborators

  • quan.jf