![](/img/trans.png)
[英]bower + gulp: main-bower-files fails to grab backbone-amd and underscore-amd?
[英]Grunt amd: true for Gulp
我正在使用以下方法进行前端应用:
要将我的模板html编译为js for handlebars我使用Grunt,并使用gruntfile.js中的那些行
handlebars: {
compile: {
options: {
processName: function (fileName) {
return path.basename(fileName, '.handlebars');
},
namespace: "Handlebars.templates",
amd: true
},
files: {
'src/templates/compiled/example.js':'src/templates/raw/example.handlebars'
}
它工作得很好,因为在我的example.js中我有第一行:
define(['handlebars'], function(Handlebars) {
似乎这行是因为amd: true
,因为如果我删除它,它就不起作用。
但问题是,在Gulp中如何在编译项目中添加此定义?
此链接解释了这一点。
用法
1.安装开发依赖项:2.将npm install --save-dev gulp-handlebars gulp-define-module
require()
语句和template
任务添加到gulpfilevar gulp = require('gulp'); var defineModule = require('gulp-define-module'); var handlebars = require('gulp-handlebars'); gulp.task('templates', function() { // Load templates from the templates/ folder relative to where gulp was executed gulp.src('source/templates/**/*.hbs') // Compile each Handlebars template source file to a template function .pipe(handlebars()) // Define templates as AMD modules .pipe(defineModule('amd')) // Write the output into the templates folder .pipe(gulp.dest('build/js/templates/')); });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.