【问题标题】:Watching coffee and jade files at the same time with grunt tasks用 grunt 任务同时看咖啡和玉文件
【发布时间】:2014-02-12 16:56:00
【问题描述】:

我想同时看我的咖啡和咕噜声文件。当我只看咖啡文件时没有问题,但是当我在我的文件中添加一个玉观察者时,观察者只编译一次,即使有更新,观察者也不会编译那些新的更新。

感谢您的帮助:

这是我的系统中只有咖啡观察者的时候:

每当咖啡文件有更新时编译:Gruntfile.coffee

module.exports = (grunt) ->

  grunt.initConfig
    pkg         : grunt.file.readJSON "package.json"

    coffee      :
      compile   :
        options : sourceMap: on
        files   :
          ['dist/client/js/main.js': 'client/app/scripts/app.coffee',
          'server.js': 'server.coffee']

    watch       :
      coffee    :
        options : atBegin: yes
        files   : [ 'client/scripts/*.coffee',
                    'client/scripts/controllers/*.coffee',
                    'server.coffee']
        tasks   : ['coffee', 'jade']


  grunt.loadNpmTasks 'grunt-contrib-coffee'
  grunt.loadNpmTasks 'grunt-contrib-watch'

  grunt.registerTask 'default', ['watch']

问题是,为什么观察者只在启动时起作用而不再起作用?

仅在启动时编译:Gruntfile.coffee

module.exports = (grunt) ->

  grunt.initConfig
    pkg         : grunt.file.readJSON "package.json"

    coffee      :
      compile   :
        options : sourceMap: on
        files   :
          ['dist/client/js/main.js': 'client/app/scripts/app.coffee',
          'server.js': 'server.coffee']

    jade: 
      compile: 
        options: 
          data: 
            debug: false
        files: 
          ['dist/client/index.html': ['client/app/views/index.jade'] ]

    watch       :
      coffee    :
        options : atBegin: yes
        files   : [ 'client/scripts/*.coffee',
                    'client/scripts/controllers/*.coffee',
                    'server.coffee']
        tasks   : ['coffee', 'jade']


  grunt.loadNpmTasks 'grunt-contrib-coffee'
  grunt.loadNpmTasks 'grunt-contrib-jade'
  grunt.loadNpmTasks 'grunt-contrib-watch'


  grunt.registerTask 'default', ['watch']

这是我的控制台注销命令:grunt --verbose

Initializing
Command-line options: --verbose

Reading "Gruntfile.coffee" Gruntfile...OK

Registering Gruntfile tasks.
Reading package.json...OK
Parsing package.json...OK
Initializing config...OK

Registering "grunt-contrib-coffee" local Npm module tasks.
Reading /Users/neva/Documents/projects/sdn-monitor/node_modules/grunt-contrib-coffee/package.json...OK
Parsing /Users/neva/Documents/projects/sdn-monitor/node_modules/grunt-contrib-coffee/package.json...OK
Loading "coffee.js" tasks...OK
+ coffee

Registering "grunt-contrib-jade" local Npm module tasks.
Reading /Users/neva/Documents/projects/sdn-monitor/node_modules/grunt-contrib-jade/package.json...OK
Parsing /Users/neva/Documents/projects/sdn-monitor/node_modules/grunt-contrib-jade/package.json...OK
Loading "jade.js" tasks...OK
+ jade

Registering "grunt-contrib-watch" local Npm module tasks.
Reading /Users/neva/Documents/projects/sdn-monitor/node_modules/grunt-contrib-watch/package.json...OK
Parsing /Users/neva/Documents/projects/sdn-monitor/node_modules/grunt-contrib-watch/package.json...OK
Loading "watch.js" tasks...OK
+ watch
Loading "Gruntfile.coffee" tasks...OK
+ default

No tasks specified, running default tasks.
Running tasks: default

Running "default" task

Running "watch" task
Waiting...Verifying property watch exists in config...OK
Verifying property watch.coffee.files exists in config...OK
Watching server.coffee for changes.
Watching .git for changes.
Watching .idea for changes.
Watching bower_components for changes.
Watching client for changes.
Watching dist for changes.
Watching node_modules for changes.
Watching server for changes.
OK

Initializing
Command-line options: --verbose

Reading "Gruntfile.coffee" Gruntfile...OK

Registering Gruntfile tasks.
Reading package.json...OK
Parsing package.json...OK
Initializing config...OK

Registering "grunt-contrib-coffee" local Npm module tasks.
Reading /Users/neva/Documents/projects/sdn-monitor/node_modules/grunt-contrib-coffee/package.json...OK
Parsing /Users/neva/Documents/projects/sdn-monitor/node_modules/grunt-contrib-coffee/package.json...OK
Loading "coffee.js" tasks...OK
+ coffee

Registering "grunt-contrib-jade" local Npm module tasks.
Reading /Users/neva/Documents/projects/sdn-monitor/node_modules/grunt-contrib-jade/package.json...OK
Parsing /Users/neva/Documents/projects/sdn-monitor/node_modules/grunt-contrib-jade/package.json...OK
Loading "jade.js" tasks...OK
+ jade

Registering "grunt-contrib-watch" local Npm module tasks.
Reading /Users/neva/Documents/projects/sdn-monitor/node_modules/grunt-contrib-watch/package.json...OK
Parsing /Users/neva/Documents/projects/sdn-monitor/node_modules/grunt-contrib-watch/package.json...OK
Loading "watch.js" tasks...OK
+ watch
Loading "Gruntfile.coffee" tasks...OK
+ default

Running tasks: coffee, jade

Running "coffee" task

Running "coffee:compile" (coffee) task
Verifying property coffee.compile exists in config...OK
Files: client/app/scripts/app.coffee -> dist/client/js/main.js
Files: server.coffee -> server.js
Options: bare=false, join=false, sourceMap, separator="\n"
Reading client/app/scripts/app.coffee...OK
Writing dist/client/js/main.js...OK
File dist/client/js/main.js created.
Writing dist/client/js/main.js.map...OK
File dist/client/js/main.js.map created (source map).
Reading server.coffee...OK
Writing server.js...OK
File server.js created.
Writing ./server.js.map...OK
File ./server.js.map created (source map).

Running "jade" task

Running "jade:compile" (jade) task
Verifying property jade.compile exists in config...OK
Files: client/app/views/index.jade -> dist/client/index.html
Options: namespace="JST", separator="\n\n", amd=false, data={"debug":false}
Reading client/app/views/index.jade...OK
Writing dist/client/index.html...OK
File "dist/client/index.html" created.

Done, without errors.
Completed in 0.731s at Wed Jan 22 2014 16:50:44 GMT+0200 (EET) - Waiting...

【问题讨论】:

    标签: node.js coffeescript sass gruntjs watch


    【解决方案1】:

    您告诉watch 关注coffee 和jade 的变化,但只在files 数组中包含coffee 文件,我认为您还需要在其中添加jade 文件以进行观看

    watch       :
      coffee    :
        options : atBegin: yes
        files   : [ 'client/scripts/*.coffee',
                    'client/scripts/controllers/*.coffee',
                    'server.coffee', 'client/app/views/index.jade'] // add the jade file here
        tasks   : ['coffee', 'jade']
    

    更新

    watch:
      coffee:
        files: ["client/scripts/*.coffee", "client/scripts/controllers/*.coffee", "server.coffee", "client/app/views/index.jade"]
        tasks: ["coffee"]
    
      jade:
        files: ["client/app/views/index.jade"]
        tasks: ["jade"]
    

    【讨论】:

    • 在“coffee”字典里面加jade任务是不是错了?
    • @ankakusu 奇怪,但没有错;似乎它们作为单独的手表会更好
    • 感谢 jcollum,这是个好建议。 dcodesmith 我试过你的建议,它奏效了。也许最好将它们放入单独的观察者中以提高可读性。
    猜你喜欢
    • 1970-01-01
    • 2015-08-10
    • 2014-03-05
    • 2014-07-16
    • 2014-07-18
    • 2015-01-02
    • 2016-06-16
    • 1970-01-01
    • 2014-08-24
    相关资源
    最近更新 更多