Grunt amd:Gulp 为真

Grunt amd: true for Gulp

我正在做一个前端应用程序使用:

为了将我的模板 html 编译为车把的 js,我使用了 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我如何在编译的项目中添加这个定义?

link 解释了这一点。

Usage

1. Install development dependencies:
npm install --save-dev gulp-handlebars gulp-define-module
2. Add the require() statements and template task to your gulpfile
var 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/'));
});