che*_*xis 6 handlebars.js gulp
我有这个错误,但这个问题和我的问题之间的不同之处在于我正在使用gulp而不是grunt.
首先,我的车把运行时是把手v4.0.5(js文件).
车把-v的输出为4.0.5
这是我的gulpfile.js:
var gulp = require('gulp');
var uglify = require('gulp-uglify');
var handlebars = require('gulp-handlebars');
var wrap = require('gulp-wrap');
var declare = require('gulp-declare');
var concat = require('gulp-concat');
gulp.task('default', ['templates','scripts'], function () {
});
gulp.task('templates', function () {
gulp.src('templates/*.hbs')
.pipe(handlebars())
.pipe(wrap('Handlebars.template(<%= contents %>)'))
.pipe(declare({
namespace: 'MyApp.templates',
noRedeclare: true, // Avoid duplicate declarations
}))
.pipe(concat('templates.js'))
.pipe(gulp.dest('js/dist'));
});
gulp.task('scripts', function () {
return gulp.src([
'bower_components/handlebars/handlebars.runtime.js',
'bower_components/jquery/dist/jquery.js',
'bower_components/bootstrap/dist/bootstrap.js',
'js/dist/templates.js',
'js/main.js'])
.pipe(concat('bundle.js'))
.pipe(uglify())
.pipe(gulp.dest('js/dist/'));
});
Run Code Online (Sandbox Code Playgroud)
Main.js
"use strict";
var data = { title: 'This Form', name: 'Joey' };
var html = MyApp.templates.hellotemplate(data);
// console.log(html);
$(document).ready(function () {
$('#dynamic-content').html(html);
});
Run Code Online (Sandbox Code Playgroud)
哪里可以成为我的问题?
错误:
未捕获错误:模板是使用旧版本的Handlebars预编译的,而不是当前运行时.请将预编译器更新为较新版本(> = 4.0.0)或将运行时降级到较旧版本(> = 2.0.0-beta.1).
我使用gulp命令预编译了模板.
非常感谢!!
小智 13
有一种更好的方法来使用特定版本的把手编译模板,自述文件中对此进行了介绍:https://github.com/lazd/gulp-handlebars#compiling-using-a-specific-handlebars-version
确保您已在应用的package.json文件中指定了把手版本:
{
"devDependencies": {
"handlebars": "^4.0.5"
}
}
Run Code Online (Sandbox Code Playgroud)
然后通过将其作为gulp文件中的gulp-handlebars选项传递来要求把手:
gulp.task('templates', function () {
gulp.src('templates/*.hbs')
.pipe(handlebars({
handlebars: require('handlebars')
}))
.pipe(wrap('Handlebars.template(<%= contents %>)'))
.pipe(declare({
namespace: 'MyApp.templates',
noRedeclare: true, // Avoid duplicate declarations
}))
.pipe(concat('templates.js'))
.pipe(gulp.dest('js/dist'));
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4011 次 |
| 最近记录: |