-
Notifications
You must be signed in to change notification settings - Fork 8
/
gulpfile.js
53 lines (48 loc) · 1.15 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const gulp = require('gulp')
const nodemon = require('gulp-nodemon')
const browserSync = require('browser-sync').create()
const config = require('./config/' + process.env.NODE_ENV)
/**
* 启动本地server
*/
gulp.task("server", function(cb) {
let started = false
let stream = nodemon({
script: './bin/www',
ext: 'js',
watch: ['server/', 'app.js'],
env: {
'NODE_ENV': config.NODE_ENV
}
})
stream.on('start', function () {
if (!started) {
cb()
started = true
}
}).on('restart', function () {
console.log('restarted!')
}).on('crash', function() {
console.error('Application has crashed!\n')
stream.emit('restart', 3) // restart the server in 3 seconds
})
})
/**
* 同步浏览器
*/
gulp.task('browser-sync', ['server'], function() {
var files = [
'server/views/**/*.html',
'server/views/**/*.hbs',
'public/static/**/*.*'
]
browserSync.init({
files: files,
proxy: 'http://localhost:' + config.port,
// browser: 'google chrome',
// notify: false,
// ui: false,
port: parseInt(config.port) + 1
})
gulp.watch(files).on('change', browserSync.reload)
})