javascript - How to require Underscore templates with Browserify + Gulp -
I am setting up a backbone project that includes the browser & amp; How do I need underscore templates (not handlebars) in my module, and it can not be ascertained, I've come to the closest "node-underscroll" (at least not seeing any other error), but it's not perfect ..
gulpfile.js
var gulp = require ('gulp'); Var requires browserify = ('Browse'); Var source = requirement ('vinyl-source-stream'); Var Buffer = Required ('Vinyl-buffer'); Var uglify = Required ('Gulappan-Eugelif'); Var gulpif = is required ('gulp-if'); Var sass = is required ('gulup-saas'); Var env = process.env.NODE_ENV || 'God'; Gulp.task ('js', function () {var bundler = browserify ({entries: [/. / Dev / js / ap.js '], path: [' ./templates/ '], conversion: [' node (Bundle .JS ') .pip (buffer) .pipe (Gulpif (NV ===' Prod ', euglyph ())). .pipe (gulp.dest ('./js/'));}); home.html
& lt; H3 & gt; Hello & lt;% = name% & gt; & Lt; / H3 & gt; Homeviz. JS (compiled from a coffee script via a different pulse function)
(function () {var $, backbone, _ = $$ = (requires 'jquery' ); _ = Is required ('underscore'); backbone = is required ('backbone'); backbone = $ = $; module.exports = backbone.view extension ({template: required ('Home. Html '), el:' #content ', initialize: function () {console.log ("home initialize"); this.render ();}, render: function () {this. $ El Html (this.template) ({Name: 'Gulp!'}); It back;}});}). Call (this); When I run the app and it hits the Home WV, the browser displays which resembles the raw JS of the module, which contains the attached template (?)
< Pre> Module.exports = function (obj) {var __t, __ p = '', __j = array.propitip.join, print = function () {__p + = __ j.call (logic, ' ');}; With (obj || {}) {__p + = 'hello' + ((__t = (name)) == faucet? '': __T) + '\ n \ n'; } Return __p; }; I tried to apply the Underscore template function to the required file, but it generates the JS error.
Template: _.template ( Required ('home .html')), Spend several hours trying different solutions, trying different solutions - any help is greatly appreciated!
I had the same problem, finally I had to work with this job, but per Ben's comment, I Instead of using the clearly defined array, I call the conversion ().
I also like to rename the bundle file and output it to the same directory as the source.
); Browser = Requirement ("Browser"); Caution = requirement ("caution"); Underscorify = requirement ("node-underscores"); Rename = Required ("Gnap-Namnam"); Source = required ("vinyl-source-stream"); Gutt = is required ("Gull-use"); Main bundler = caution (browserfix (". / Js / main.js")); MainBundler.transform (underscorify.transform ()); Gulp.task ("surveillance-main", bundle man); Mainbundler ("Update", Bundle Man); Main bundler. ("Log", guttle.lag); Return to Function Bundleman () {mainBundler.bundle (). ("Error", gutil.log.bind ("browser error")) .pipe (source (".js / main.js")) .pipe (rename ("main-bundle .js") ) .pipe (gulp.dest ("./Js /")); }; gulp = require ("gulp")
home.html
& lt; H3 & gt; Hello & lt;% = name% & gt; & Lt; / H3 & gt; main.js
template = required (". / Templates / home.html"); Module.exports = backbone.View.extend ({Template: Template, L: "#content", initialize: function () {// initialize code}, render: function () {// render code}});
Comments
Post a Comment