我正在设置一个我正在尝试的Grunt文件:
我有前两个步骤使用它:
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')?
此外,服务器使用快递 - 重新启动应用程序需要在启动之前查看该端口是否再次可用?
答案 0 :(得分: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']