A gulp plugin for exporting contents as string.
$ npm install --save-dev gulp-js-string
var jsString = require('gulp-js-string');
gulp.src('./views/*.bhtml')
.pipe(jsString())
.pipe(gulp.dest('./dist'));
Input: index.html
:
<p>meow...meow...</p>
Output: index.js
:
module.exports = '<p>meow...meow...</p>';
Optionally, the format can be configured:
var jsString = require('gulp-js-string');
gulp.src('./views/*.bhtml')
.pipe(jsString(function(escapedString, file) {
var varname = file.basename.split('.')[0];
return 'exports.' + varname + ' = \'' + escapedString + '\';';
}))
.pipe(gulp.dest('./dist'));
Input: index.html
:
<p>meow...meow...</p>
Output: index.js
:
exports.index = '<p>meow...meow...</p>';
This is espacially useful if used in combination with gulp-concat
to merge several files.