简体   繁体   中英

A single Grunt task to run a shell command and watch task?

Given this Gruntfile.coffee , I'd like to keep the shell:server task running and outputting to the shell while watch checks for changes to front-end assets and reports to the shell when it runs my :compile tasks.
All from the same grunt command to the same 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'])

A bonus would be eliminating supervisor in favor of using Grunt to watch for server changes and rebooting the web server.

Options:

  1. see if one of the tasks provides a background: true option (grunt-karma does, for example, IIRC)

  2. look into grunt-parallel

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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