js
file.template_file_name
is the HTML file name.
var templates = {
template_file_name : '...template HTML string...',
template_file_name2 : '...template HTML string...',
template_file_name3 : '...template HTML string...'
}
I don't really know how to approach this, and how to create such text from all the files..yes I can convert each individual file to a string, but how can I put it inside an object?
For those who want your templates as ES6 modules, I have created gulp-file-contents-to-modules
export var file_name = "This is bar.";
export var file_name2 = "This is foo.\r\n";
export var my-folder__file_name = "This is baz.\r\n";
I've found this wonderful tool which does exactly what I want:
https://www.npmjs.org/package/gulp-template-compile
gulp.task('templates', function () {
gulp.src('./views/templates/**/*.html')
.pipe(template()) // converts html to JS
.pipe(concat('templates.js'))
.pipe(gulp.dest('./js/dist/'))
});
Then you can access the key/value object with window.JST
. The values are functions (I don't know why, but it's like that)
I've decided to use use gulp-file-contents-to-json which is the most simple thing possible for generating JSON from files' contents.
I've created 3 NPM packages (might be handy to someone):
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With