-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
132 lines (115 loc) · 3.43 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
var gulp = require('gulp')
, gutil = require('gulp-util')
, rimraf = require('gulp-rimraf')
, 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')
, streamify = require('gulp-streamify')
, uglify = require('gulp-uglify')
, connect = require('gulp-connect')
, source = require('vinyl-source-stream')
, browserify = require('browserify')
, watchify = require('watchify')
, gulpif = require('gulp-if')
, coffee = require('gulp-coffee')
, paths;
var watching = false;
paths = {
assets: 'src/assets/**/*',
css: 'src/css/*.css',
libs: [
'./src/bower_components/phaser-official/build/phaser.js'
],
coffee: './src/scripts/**/*.coffee',
jsdest: './src/js',
js: ['src/js/*.js', 'src/js/**/*.js'],
entry: './src/js/main.js',
dist: './dist/'
};
gulp.task('clean', function () {
return gulp.src(paths.dist, {read: false})
.pipe(rimraf({ force: true }))
.on('error', gutil.log);
});
gulp.task('copy', ['clean'], function () {
gulp.src(paths.assets)
.pipe(gulp.dest(paths.dist + 'assets'))
.on('error', gutil.log);
});
gulp.task('copylibs', ['clean'], function () {
gulp.src(paths.libs)
.pipe(gulpif(!watching, uglify({outSourceMaps: false})))
.pipe(gulp.dest(paths.dist + 'js/lib'))
.on('error', gutil.log);
});
gulp.task('coffee', ['clean'], function() {
gulp.src(paths.coffee)
.pipe(coffee({bare:true}).on('error', gutil.log))
.pipe(gulp.dest(paths.jsdest))
.on('error', gutil.log);
});
gulp.task('compile', ['clean'], function () {
var bundler = browserify({
cache: {}, packageCache: {}, fullPaths: true,
entries: [paths.entry],
debug: watching
});
var bundlee = function() {
return bundler
.bundle()
.pipe(source('main.min.js'))
.pipe(jshint('.jshintrc'))
.pipe(jshint.reporter('default'))
.pipe(gulpif(!watching, streamify(uglify({outSourceMaps: false}))))
.pipe(gulp.dest(paths.dist))
.on('error', gutil.log);
};
if (watching) {
bundler = watchify(bundler);
bundler.on('update', bundlee)
}
return bundlee();
});
gulp.task('minifycss', ['clean'], function () {
gulp.src(paths.css)
.pipe(gulpif(!watching, minifycss({
keepSpecialComments: false,
removeEmpty: true
})))
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest(paths.dist))
.on('error', gutil.log);
});
gulp.task('processhtml', ['clean'], function() {
return gulp.src('src/index.html')
.pipe(processhtml('index.html'))
.pipe(gulp.dest(paths.dist))
.on('error', gutil.log);
});
gulp.task('minifyhtml', ['processhtml'], function() {
gulp.src('dist/index.html')
.pipe(gulpif(!watching, minifyhtml()))
.pipe(gulp.dest(paths.dist))
.on('error', gutil.log);
});
gulp.task('html', ['build'], function(){
gulp.src('dist/*.html')
.pipe(connect.reload())
.on('error', gutil.log);
});
gulp.task('connect', function () {
connect.server({
root: ['./dist'],
port: 9050,
livereload: true
});
});
gulp.task('watch', function () {
watching = true;
return gulp.watch(['./src/index.html', paths.css, paths.coffee], ['build', 'html']);
});
gulp.task('default', ['connect', 'watch', 'build']);
gulp.task('build', ['clean', 'copy', 'copylibs', 'coffee', 'compile', 'minifycss', 'processhtml', 'minifyhtml']);