Codd Wrench Codd Wrench - 4 months ago 10
Node.js Question

Using gulp for insert html in js

I have two files, js

(function (Controllers) {
var DialogElement = (function () {
function DialogElement() {
this._template = "include:'Views/Dialog.html'";
}
return DialogElement;
}());
Controllers.DialogElement = DialogElement;
})(Controllers));


and html

<div>Simple dialog!</div>


I want used gulp replaces variable
this._template = "include:'Views/Dialog.html'";
on the contents of the html file.

To get so:

function DialogElement() {
this._template = "<div>Simple dialog!</div>";
}


May be there is a plugin suitable for this?

Answer

I learned gulp-html2js and gulp-inject, but they work not as expected.

So i make your salf package and and use it as:

gulp.task('inject', function () {
    gulp
        .src('Controllers/*.js')
        .pipe(inject('Views/*.html'))
        .pipe(gulp.dest('build'));
});

and chenge controller:

this._template = "{{load path='Views/Dialog.html'}}"  
Comments