Javascript gulp车把中未定义车把
我需要安装什么才能使其正常工作?我有一个这样的结构Javascript gulp车把中未定义车把,javascript,templates,npm,gulp,handlebars.js,Javascript,Templates,Npm,Gulp,Handlebars.js,我需要安装什么才能使其正常工作?我有一个这样的结构 index.html gulpfile.js 模板/ frontPage.html 剧本/ main.js handlebar.js 在我的index.html中,我有(我在head中包括了jQuery) 然后我尝试在handlebar.js中使用它,就像 "use strict"; // var data = { title: 'This Form', name: 'Joey' }; var frontPage = GD.temp
- index.html
- gulpfile.js
- 模板/
- frontPage.html
- 剧本/
- main.js
- handlebar.js
"use strict";
// var data = { title: 'This Form', name: 'Joey' };
var frontPage = GD.templates.frontPage;
console.log(frontPage);
console.log($('#front-page'));
$(document).ready(function () {
$('#front-page').html(frontPage);
});
问题是我的template.js第3行中没有定义把手。我试过npm安装车把,但没用。我不确定我错过了什么,但我想在这方面得到一些帮助。。这让我发疯。我在index.html中包含了
,并将我的package.json更改为包含开发依赖项{handlebar:4.0.4}
,安装了npm安装把手
并将gulpfile更改为.pipe(handlebar({handlebar:require('handlebar')}))
,然后我才让它工作起来。感觉好像我一直在使用一些我不需要的额外的东西,但我不知道我真正需要什么和我不再需要什么。大脑故障过载等。我在index.html中包含了
,并将我的package.json更改为包含开发依赖项{handlebar:4.0.4}
,安装了npm安装把手
,并将gulpfile更改为.pipe(handlebar({handlebar:require('handlebar')}))
,直到那时我才让它工作起来。感觉好像我一直在使用一些我不需要的额外的东西,但我不知道我真正需要什么和我不再需要什么。脑功能紊乱、过载等。
// Handlebars
gulp.task('templates', function(){
gulp.src('templates/*.html')
.pipe(handlebars())
.pipe(wrap('Handlebars.template(<%= contents %>)'))
.pipe(declare({
namespace: 'GD.templates',
noRedeclare: true, // Avoid duplicate declarations
}))
.pipe(concat('templates.js'))
.pipe(gulp.dest('build/scripts/'));
});
this["GD"] = this["GD"] || {};
this["GD"]["templates"] = this["GD"]["templates"] || {};
this["GD"]["templates"]["frontPage"] = Handlebars.template({"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) {
return "... html content not relevant ...";
},"useData":true});
"use strict";
// var data = { title: 'This Form', name: 'Joey' };
var frontPage = GD.templates.frontPage;
console.log(frontPage);
console.log($('#front-page'));
$(document).ready(function () {
$('#front-page').html(frontPage);
});