【发布时间】:2013-10-18 18:49:25
【问题描述】:
我在使用 Grunt.js 和一些插件时遇到了问题,特别是:grunt-contrib-watch、grunt-nodemon 和 grunt-contrib-coffee。这两天我一直在尝试解决这个问题,但我认为我对 Grunt 的了解不足以解决这个问题。
我遇到的问题只是我希望我的服务器端 .coffee 文件能够编译,然后让 nodemon 重新启动服务器,然后只有 livereload 工作。现在,Livereload 可以按预期工作,但服务器端 coffee 文件除外。 contrib-watch 检测到更改,运行 coffee 并触发 livereload 事件,但随后 nodemon 重新启动。
有没有办法让nodemon 在页面重新加载之前重新启动,以便我在屏幕上看到的内容与我的服务器端代码中的内容保持同步?
我已经看到了在单独的终端选项卡中运行 nodemon 的选项,但我在 Windows 上并且更愿意为此目的保持一个终端运行,这就是我使用的全部原因grunt-concurrent.
这是我的 Gruntfile,它还处于早期阶段(因为我试图弄清楚这一切)。如果您希望我将其编译为 JavaScript,那么只需发表评论并提出请求,我将很乐意。
module.exports = (grunt) ->
# configuration
grunt.initConfig
pkg: grunt.file.readJSON 'package.json'
# watch task
watch:
css:
files: ['src/assets/styles/**/*.styl']
tasks: ['stylus']
options:
livereload: true
coffee:
files: ['src/**/*.coffee']
tasks: ['coffee']
js:
files: ['**/*.js']
options:
livereload: true
jade:
files: ['views/**/*.jade']
options:
livereload: true
# compile coffeescript to javascript
coffee:
compile:
options:
sourceMap: true
files: [
expand: true
cwd: 'src/'
src: ['**/*.coffee']
dest: ''
ext: '.js'
]
# compile stylus to css
stylus:
compile:
files: [
expand: true
cwd: 'src/assets/styles/'
src: ['**/*.styl']
dest: 'assets/styles/'
ext: '.css'
]
# run server
nodemon:
dev:
options:
file: 'server.js'
watchedExtensions: ['js', 'json']
ignoredFiles: [
'assets/**',
'node_modules/**',
'**/.js.map'
]
# run tasks concurrently for fast builds
concurrent:
first:
tasks: ['coffee', 'stylus']
options:
logConcurrentOutput: true
second:
tasks: ['nodemon', 'watch']
options:
logConcurrentOutput: true
# load dependencies
require('load-grunt-tasks') grunt
# register tasks
grunt.registerTask 'default', [
'concurrent:first',
'concurrent:second'
]
【问题讨论】:
标签: gruntjs grunt-contrib-watch grunt-concurrent