简体   繁体   English

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

[英]handlebars:compile - Cannot read property 'filter' of undefined use

I've been searching around but there seemed to be no situation similar to mine so thought I'd post to ask. 我一直在寻找,但似乎没有类似于我的情况,所以我想发帖询问。 I want to run the handlebars task in Gruntfile.js with grunt handlebars to compile a templates.js in my source folder (www) but it doesn't fire up with this error shown: 我想运行与咕噜车把 Gruntfile.js车把任务来编译我的源文件夹(www)的templates.js,但它不显示此错误火了:

Warning: Cannot read property ' filter ' of undefined Use 警告:无法读取未定义的属性“ 过滤器 ”使用

Here's my script for the handlebars task in grunt file: 这是我在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'
    }
  }
});

Here's opening script of grunt file and the config object, before grunt.initConfig : 这是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
    };
});

Couldn't figure out what goes wrong here since I don't even define a property/term filter and that's the only error received. 无法弄清楚这里出了什么问题,因为我甚至没有定义属性/术语过滤器,这是唯一收到的错误。 Any thoughts would be appreciated. 任何想法将不胜感激。

So I will write what I did to resolve this which might be of use to you. 所以我会写下我为解决这个问题而做的事情,这可能对你有用。

I simply changed the www property specifically to src , as referred to in the first code block, for the handlebars task in grunt file to fire up. 我只是将www属性专门改为src ,如第一个代码块中所提到的,用于启动grunt文件中的把手任务。 Existing handlebars which are markups are sourced aka src and to compile the templates.js in your specified destination. 作为标记的现有把手源自 src并且在您指定的目的地中编译templates.js。

Note: handlebars file itself should end with unspecified file type (.handlebars). 注意:把手文件本身应以未指定的文件类型(.handlebars)结束。 Depending on your own set up, noting this will save you lots of time afterwards. 根据您自己的设置,注意这将节省您很多时间。

Now run below and you shall see the templates.js found in the dest folder. 现在在下面运行,您将看到dest文件夹中找到的templates.js。

grunt handlebars 咕噜的车把

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM