【问题标题】:grunt watch changes and restart coffeegrunt 监视更改并重新启动咖啡
【发布时间】:2014-08-24 07:35:26
【问题描述】:

我正在设置一个 Gruntfile,我正在尝试:

  1. 一些咖啡脚本编译为客户端的javascript。
  2. 注意要编译为客户端 javascript 的咖啡脚本的更改。
  3. 注意后端(服务器)coffeescript 文件的更改,并在发现更改时重新启动咖啡应用程序。

我已经完成了前两个步骤:

module.exports = (grunt) ->
  grunt.initConfig
    pkg: grunt.file.readJSON 'package.json'
    coffee:
      compile:
        expand: true
        flatten: true
        cwd: 'public/src'
        src: ['*.coffee']
        dest: 'public/dist'
        ext: '.js'
    watch:
      coffee:
        files: ['public/src/*.coffee']
        tasks: ['coffee']

  grunt.loadNpmTasks 'grunt-contrib-coffee'
  grunt.loadNpmTasks 'grunt-contrib-watch'
  grunt.registerTask 'default', ['coffee', 'watch']

但我不知道如何进行第三步。

目前目录结构如下:

app
  lib.coffee
  routes.coffee
public/
  dist/
    client.js
  src/
    client.coffee
Gruntfile.coffee
package.json
server.coffee

我如何观察 app 目录或 server.coffee 文件中的任何内容的更改并使用 grunt 自动启动服务器(例如“coffee server.coffee”)?

服务器也使用 express - 重新启动应用程序是否需要在启动之前查看端口是否再次可用?

【问题讨论】:

    标签: coffeescript gruntjs grunt-contrib-watch grunt-contrib-coffee


    【解决方案1】:

    最终设法让这个工作:

    module.exports = (grunt) ->
      grunt.initConfig
        pkg: grunt.file.readJSON 'package.json'
        coffee:
          compile:
            expand: true
            flatten: true
            cwd: 'public/src'
            src: ['*.coffee']
            dest: 'public/dist'
            ext: '.js'
        watch:
          coffee:
            files: ['public/src/*.coffee']
            tasks: ['coffee']
          express:
            files: ['server.coffee']
            tasks: ['express:dev']
            options:
              spawn: false
        express:
          dev:
            options:
              script: 'server.coffee'
              opts: ['/path/to/coffee']
              #port: 8080
    
      grunt.loadNpmTasks 'grunt-contrib-coffee'
      grunt.loadNpmTasks 'grunt-contrib-watch'
      grunt.loadNpmTasks 'grunt-express-server'
      grunt.registerTask 'default', ['coffee', 'express:dev', 'watch']
    

    【讨论】:

      猜你喜欢
      • 2015-08-27
      • 1970-01-01
      • 2014-03-05
      • 2021-05-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多