-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
92 lines (84 loc) · 2.77 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
var gulp = require('gulp')
, gutil = require('gulp-util')
, del = require('del')
, concat = require('gulp-concat')
, rename = require('gulp-rename')
, minifycss = require('gulp-minify-css')
, minifyhtml = require('gulp-minify-html')
, processhtml = require('gulp-processhtml')
, jshint = require('gulp-jshint')
, uglify = require('gulp-uglify')
, connect = require('gulp-connect')
, nodemon = require('gulp-nodemon') // Restart the app
, livereload = require('gulp-livereload') // Reload browser after restart
, notify = require('gulp-notify')
, browserify = require('gulp-browserify')
, watchify = require('watchify')
, buffer = require('vinyl-buffer')
, source = require('vinyl-source-stream')
, paths;
// Path of static files like css, html, js
paths = {
libs: ['src/client/bower_components/phaser-official/build/phaser.min.js']
, html: ['src/client/views/**/*.jade', 'src/client/views/**/*.html']
, css: 'src/client/css/*.css'
, js: ['src/client/js/**/*.js', 'src/server/*.js']
, img: 'src/client/img'
, dist: 'src/client/dist/'
, entry: 'src/client/js/main.js'
};
// Clean auto-generated dist folder
gulp.task('clean', function (cb) {
del([paths.dist]);
cb(null); // Give a hint when task finished
});
// Minify and rename CSS files, then output them to dist/css folder
gulp.task('minifycss', ['clean'], function () {
gulp.src(paths.css)
.pipe(minifycss({
keepSpecialComments: false,
removeEmpty: true
}))
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest(paths.dist + 'css'))
.on('error', gutil.log);
});
// Lint js files and log errors
gulp.task('lint', function() {
gulp.src(paths.js)
.pipe(jshint('.jshintrc'))
.pipe(jshint.reporter('default'))
.on('error', gutil.log);
});
// Browserify all js modules into one file
gulp.task('browserify', function () {
gulp.src(paths.entry)
.pipe(browserify({
debug : true
}))
//.pipe(uglify())
.pipe(gulp.dest(paths.dist + 'js'));
});
// Build before start server, rebuild and restart server in nodemon
// when files are modified.
gulp.task('runserver', ['build'], function(cb){
// ! livereload is still not working, press CMD + R instead
livereload.listen();
nodemon({
script: 'src/server/app.js'
, ext: 'css js jade'
, tasks: ['build']
, ignore: ['src/client/dist/**/*.js', 'src/client/dist/**/*.css']
}).on('restart', function(){
gulp.src('src/server/app.js')
.pipe(livereload())
//.pipe(notify('Reloading page, please wait...'));
});
});
// Event listener on change of static files
gulp.task('watch', function () {
gulp.watch(paths.js, ['lint']);
gulp.watch(paths.css, ['minifycss']);
});
gulp.task('default', ['runserver', 'watch']);
gulp.task('build', ['browserify', 'minifycss']);