javascript - combine html template files into one JS file -
- i have html template files (underscore template syntax)
- these files saved in html format easy edit (ide syntax highlight)
- i don't want fetch them ajax, rather combine them , include them a
js
file. - using gulp task-runner, somehow combine all html this, javascript file include in build process:
template_file_name
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 know how approach this, , how create such text files..yes can convert each individual file string, how can put inside object?
update - oct 25, 15 - es6 modules:
for want templates es6 modules, have created gulp-file-contents-to-modules
demo output:
export var file_name = "this bar."; export var file_name2 = "this foo.\r\n"; export var my-folder__file_name = "this baz.\r\n";
all npm packages related combining template files using gulp:
i've found wonderful tool want:
https://www.npmjs.org/package/gulp-template-compile
usage (as simple as):
gulp.task('templates', function () { gulp.src('./views/templates/**/*.html') .pipe(template()) // converts html js .pipe(concat('templates.js')) .pipe(gulp.dest('./js/dist/')) });
then can access key/value object window.jst
. values functions (i don't know why, it's that)
update - august 21, 2015
i've decided use use gulp-file-contents-to-json simple thing possible generating json files' contents.
update - july 19, 2016
i've created 3 npm packages (might handy someone):
Comments
Post a Comment