-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
85 lines (73 loc) · 2.27 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
var gulp = require('gulp');
var browserSync = require('browser-sync');
var watch = require('gulp-watch');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var eslint = require('gulp-eslint');
var sourcemaps = require('gulp-sourcemaps');
/**
* Runs a web server
* - reloads css/audio/images upon change
* - reloads page on changed index.html
* - upon changed js files (except bundle.js and bundle.min.js),
* bundle files are rebuilt and then page is reloaded.
*/
gulp.task('webserver', function() {
browserSync({
notify: false,
open: false,
port: 9000,
reloadDelay: 0, // [ms]
ghostMode: false, // Cause more trouble than help for Monster Tower.
server: {
baseDir: 'www',
}
});
gulp.watch([
'www/index.html',
]).on('change', function() {browserSync.reload()});
gulp.watch([
'www/audio/**/*',
]).on('change', function() {browserSync.reload('www/audio/**/*')});
gulp.watch([
'www/css/*.css',
]).on('change', function() {browserSync.reload('www/css/*.css')});
gulp.watch([
'www/images/**/*',
]).on('change', function() {browserSync.reload('www/images/**/*')});
gulp.watch([
'www/js/*.js',
'!www/js/bundle.js',
'!www/js/bundle.min.js',
], ['on_js_change']);
});
// re-builds bundle and then cause browser to reload.
gulp.task('on_js_change', ['lint_js', 'bundle_js'], function() {
browserSync.reload(); // reload full page.
});
// Bundles, minifies JS and produce source maps.
gulp.task('bundle_js', function() {
return gulp.src(['www/js/!(main)*.js', 'www/js/main.js', '!www/js/bundle.js', '!www/js/bundle.min.js'])
.pipe(sourcemaps.init())
// bundle:
.pipe(concat('bundle.js'))
.pipe(gulp.dest('./www/js/'))
// minify:
.pipe(uglify({
compress: false,
}))
.pipe(sourcemaps.write())
.pipe(rename({extname: '.min.js'}))
.pipe(gulp.dest('./www/js/'));
});
gulp.task('lint_js', function() {
return gulp.src(['www/js/*.js', '!www/js/bundle.js', '!www/js/bundle.min.js', '!www/js/jquery-1.11.3.min.js'])
.pipe(eslint())
.pipe(eslint.format('compact'));
});
gulp.task('watch', function() {
// watch tasks to re-build files
gulp.watch(['www/js/*.js', '!www/js/bundle.js', '!www/js/bundle.min.js'], ['bundle_js']);
});
gulp.task('default', ['bundle_js', 'webserver', 'watch']);