handlebars:compile - 无法读取未定义使用的属性“过滤器”

时间:2016-10-11 19:20:47

标签: javascript gruntjs handlebars.js

我一直在寻找,但似乎没有类似于我的情况,所以我想发帖询问。我想在Gruntfile.js中使用 grunt handlebars 运行把手任务,以便在我的源文件夹(www)中编译templates.js,但它不会显示此错误:

  

警告:无法读取未定义的属性“过滤器”使用

这是我在grunt文件中处理把手任务的脚本:

// Create the tasks
grunt.initConfig({

  config: config,

  handlebars: {
    // Compiles the handlebar templates into templates.js
    compile: {
      options: {
        amd: true,
        processName: function (filepath) {
          var pieces = filepath.split('/');
          return pieces[pieces.length - 1].split('.')[0];
        }
      },
      // Specify location of handlebar templates
      www: ['<%= config.www %>/html/{,*/}*.handlebars'],
      dest: '<%= config.www %>/js/templates.js'
    }
  }
});

这是grunt文件和配置对象的开始脚本,在grunt.initConfig之前:

module.exports = (function () {

    'use strict';

    return function (grunt) {

      require('load-grunt-tasks')(grunt); // Several tasks to run using grunt-contrib-xx plugins

      // Config object
      var config = {
        www: 'www',                // all source files in one directory
      };
        ..                        // grunt.initConfig
    };
});

无法弄清楚这里出了什么问题,因为我甚至没有定义属性/术语过滤器,这是唯一收到的错误。任何想法都将不胜感激。

1 个答案:

答案 0 :(得分:0)

所以我会写下我为解决这个问题而做的事情,这可能对你有用。

我只是将 www 属性专门更改为 src ,如第一个代码块中所述,用于启动grunt文件中的把手任务。作为标记的现有把手是来源 a.k.a. src并编译指定目的地的templates.js。

注意:把手文件本身应以未指定的文件类型(.handlebars)结束。根据您自己的设置,注意这将为您节省大量时间。

现在在下面运行,您将看到 dest 文件夹中的templates.js。

  

grunt车把

相关问题