首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >gruntjs棘手的配置

gruntjs棘手的配置
EN

Stack Overflow用户
提问于 2013-02-22 18:51:33
回答 1查看 712关注 0票数 1

我想知道如何查看这里的文件:

代码语言:javascript
运行
复制
module.exports = function(grunt) {

  grunt.loadNpmTasks('grunt-contrib-watch');
  grunt.loadNpmTasks('grunt-contrib-handlebars');

  // Project configuration.
  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    handlebars: {
      compile: {
        files: {
          "app/handlebars/handlebars-templates.js" : [
            "app/handlebars/*.handlebars"
          ]
        }
      }
    },
    watch: {
      handlebars: {
        files: [
          '<%= handlebars.compile.files %>' <== what to put here ?
        ],
        tasks: 'default'
      }
    }
  });

  grunt.registerTask('default', 'handlebars');
};

我可以放入“app/handlebar/*.handlebar”,但我想写一些动态地采用正确路径的东西

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-02-24 07:24:47

配置中的<%= handlebars.compile.files %>指向一个对象。所以手表并不知道你真正想要的是哪些文件。尝试像这样添加/读取配置变量:

代码语言:javascript
运行
复制
grunt.initConfig({
  pkg: grunt.file.readJSON('package.json'),
  handlebars_path: "app/handlebars/*.handlebars",
  handlebars: {
    compile: {
      files: {
        "app/handlebars/handlebars-templates.js" : [
          "<%= handlebars_path %>"
        ]
      }
    }
  },
  watch: {
    handlebars: {
      files: [
        "<%= handlebars_path %>"
      ],
      tasks: 'default'
    }
  }
});

或者使用更明确的配置:

代码语言:javascript
运行
复制
handlebars: {
  compile: {
    src: ['app/handlebars/*.handlebars'],
    dest: 'app/handlebars/handlebars-templates.js'
  }
}

<%= handlebars.compile.src %>在一起。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15022455

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档