我正在尝试使用gulp
使用快速服务器进行实时重新加载然而gulp在运行后退出如下,并且无法点击服务器
cmd输出:
D:\ Users \ workspace \ server> gulp服务器 [11:31:56]使用gulpfile D:\ Users \ workspace \ server \ gulpfile.js
[11:31:56]开始'服务器' ...
[11:31:56]已完成的服务器' 26毫秒后
livereload [tiny-lr]收听35729 ...
d:\ Users \用户工作空间\服务器>
gulpfile.js:
var gulp = require('gulp');
var server = require('gulp-express');
gulp.task('server', function () {
// Start the server at the beginning of the task
server.run(['app.js']);
// Restart the server when file changes
gulp.watch(['app/**/*.html'], server.notify);
gulp.watch(['app/styles/**/*.scss'], ['styles:scss']);
//gulp.watch(['{.tmp,app}/styles/**/*.css'], ['styles:css', server.notify]);
//Event object won't pass down to gulp.watch's callback if there's more than one of them.
//So the correct way to use server.notify is as following:
gulp.watch(['{.tmp,app}/styles/**/*.css'], function(event){
gulp.run('styles:css');
server.notify(event);
//pipe support is added for server.notify since v0.1.5,
//see https://github.com/gimm/gulp-express#servernotifyevent
});
gulp.watch(['app/scripts/**/*.js'], ['jshint']);
gulp.watch(['app/images/**/*'], server.notify);
gulp.watch(['app.js', 'routes/**/*.js'], [server.run]);
});
gulp.task('default', ['server']);
我称之为gulp的方式是否存在根本不正确的事情?
答案 0 :(得分:0)
即使我有一些问题让实时重新加载工作。因此我开始使用gulp-nodemon来创建网络服务器和实时重新加载。以下是我的任务:
gulp.task('server', function(){
var nodeOptions = {
script:"",//path to the app.js or server.js
delayTime: 1,
env: {
'PORT': 8088 //port that you want to run it on
},
watch: ['filesToBeWatched.js'] //files to be watched for changes
};
return nodemon(nodeOptions)
.on('restart', function(event){
console.log('Node Server RESTARTED');
})
.on('start', function(){
console.log('Node Server STARTED');
startBrowserSync();
})
.on('crash', function() {
console.log('Node Server CRASHED');
})
.on('exit', function() {
console.log('Node Server EXISTED')
});
});