我最終不得不用自己的孩子進程。 Nodemon將阻止監測發生,並且不夠靈活以處理重新編譯步驟。
這是我的Gruntfile,使用watch,copy,clean和TypeScript模塊。
var loader = require('load-grunt-tasks');
var cp = require('child_process');
module.exports = function (grunt) {
loader(grunt, {});
grunt.initConfig({
tsFiles: [
"**/*.ts",
"!typings/**/*.ts",
"typings/tsd.d.ts",
"!build/**/*.ts",
"!bower_modules/**/*.ts",
"!node_modules/**/*.ts",
],
buildDir: 'build/',
clean: {
build: '<%= buildDir %>'
},
ts: {
build: {
src: [
"**/*.ts",
"!typings/**/*.ts",
"typings/tsd.d.ts",
"!build/**/*.ts",
"!bower_modules/**/*.ts",
"!node_modules/**/*.ts",
],
outDir: '<%= buildDir %>',
options: {
"target": 'ES5',
"module": 'commonjs',
"sourceMap": true,
}
}
},
copy: {
build: {
expand: true,
cwd: './',
src: [
'*.json',
'config/**/*.json',
'test/**/*.js'
],
dest: '<%= buildDir %>/',
filter: 'isFile'
}
},
watch: {
run: {
files: [
'**/*.ts',
'**/*.js',
'**/*.json',
'!.*/**/*.*',
'!build/**/*.*',
'!node_modules/**/*.*',
'!logs/**/*.*'
],
tasks: ['server-stop', 'build', 'server-restart'],
options: {
spawn: false
}
}
}
});
var child = null;
function killChild(){
if (child){
child.kill();
child.disconnect();
child = null;
}
}
grunt.registerTask('server-stop', 'Stop the dev server', function(){
killChild();
});
grunt.registerTask('server-restart', 'Stop the dev server', function(){
killChild();
child = cp.fork('./build/app.js');
});
grunt.registerTask('build', ['copy', 'ts']);
grunt.registerTask('rebuild', ['clean', 'build']);
grunt.registerTask('default', ['rebuild']);
grunt.registerTask('run', ['default', 'server-restart', 'watch']);
};
看,可能是預期,但沒有咕嚕...... https://www.npmjs.com/package/gulp-connect – Synoon
一個很好的解決方案不幸的是,連接不是我所需要的。我不需要Web服務器,因爲我們是一個自定義的服務器進程。 – jocull