【问题标题】:Using gruntjs, how do watch for changes in .coffee files?使用 grunt js,如何观察 .coffee 文件的变化?
【发布时间】:2012-09-30 13:55:29
【问题描述】:

我是 gruntjs 的新手,这是我的简单 gruntfile:

/* global module:false */
module.exports = function(grunt) {

  // Project configuration.
  grunt.initConfig({
    watch: {
      tasks: 'coffee'
    },
    coffee: {
      compile: {
        files: {
          'js/javascript/*.js': ['js/coffeescript/*.coffee'] // 1:1 compile
        }
      }
    }
  });

  grunt.loadNpmTasks('grunt-contrib-coffee');

  // Default task.
  grunt.registerTask('default', 'coffee');
};

当我运行 grunt 时,它编译得很好。但是,当我运行 grunt watch 时,它只是在等待并没有检测到我的更改。

【问题讨论】:

  • 您是否尝试定义“...任务:'coffee -w' ...”?

标签: javascript coffeescript gruntjs


【解决方案1】:

您应该添加要观看的文件:

watch: {
  coffee: {
    files: ['js/coffeescript/*.coffee'],
    tasks: 'coffee'
  }
}

来自example

【讨论】:

  • 那行得通。谢谢你。还有一个问题,在编译的js文件夹中保留coffee文件夹的文件夹结构而不必列出应用程序的所有coffeescript文件夹的语法是什么?
  • 可以使用 Grunt 的不稳定 alpha 版本 v0.4a 来完成,但仍在讨论中。看看这个线程:github.com/gruntjs/grunt-contrib-coffee/pull/1
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-02-11
  • 1970-01-01
  • 1970-01-01
  • 2018-11-18
  • 1970-01-01
相关资源
最近更新 更多