【问题标题】:A single Grunt task to run a shell command and watch task?运行 shell 命令和监视任务的单个 Grunt 任务?
【发布时间】:2013-12-12 15:45:08
【问题描述】:

鉴于此Gruntfile.coffee,我想保持shell:server 任务运行并输出到shell,而watch 检查前端资产的更改并在运行我的:compile 时向shell 报告任务。
全部来自同一个grunt 命令到同一个shell。

module.exports = (grunt) ->
  grunt.initConfig
    pkg: grunt.file.readJSON('package.json')

    coffee:
      compile:
        files:
          'public/js/app.js': 'assets/js/app.coffee'

    stylus:
      compile:
        files:
          'public/css/app.css': 'assets/css/app.styl'

    watch:
      css:
        files: 'assets/**/*.styl'
        tasks: 'stylus'
      javascript:
        files: 'assets/**/*.coffee'
        tasks: 'coffee'

    shell:
      server:
        command: 'supervisor index.coffee'
        options:
          stdout: true

  grunt.loadNpmTasks('grunt-contrib-coffee')
  grunt.loadNpmTasks('grunt-contrib-stylus')
  grunt.loadNpmTasks('grunt-contrib-watch')
  grunt.loadNpmTasks('grunt-shell')

  grunt.registerTask('work', ['default', 'shell:server', 'watch'])
  grunt.registerTask('default', ['coffee', 'stylus'])

一个好处是取消supervisor,转而使用 Grunt 监视服务器更改并重新启动 Web 服务器。

【问题讨论】:

    标签: node.js gruntjs grunt-contrib-watch


    【解决方案1】:

    选项:

    1. 查看其中一项任务是否提供background: true 选项(grunt-karma 提供,例如 IIRC)

    2. 查看grunt-parallel

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-05-14
      • 1970-01-01
      • 2014-02-17
      • 1970-01-01
      • 2013-02-23
      • 1970-01-01
      • 1970-01-01
      • 2015-07-28
      相关资源
      最近更新 更多