-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathgulpfile.js
More file actions
90 lines (79 loc) · 2.47 KB
/
Copy pathgulpfile.js
File metadata and controls
90 lines (79 loc) · 2.47 KB
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
var gulp = require('gulp');
var clean = require('gulp-clean');
var browserify = require('browserify');
var watchify = require('watchify');
var source = require('vinyl-source-stream');
var babelify = require('babelify');
var runSequence = require('run-sequence');
var stringify = require('stringify');
var sass = require('gulp-sass');
var cssify = require('cssify');
var autoprefixer = require('gulp-autoprefixer');
var plumber = require('gulp-plumber');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
gulp.task('minify', function() {
return gulp.src('./build/phaser-inspector.js')
.pipe(rename('phaser-inspector.min.js'))
.pipe(uglify({ mangle: false }))
.pipe(gulp.dest('./build'));
});
gulp.task('css', function () {
return gulp.src('./src/css/**/*.sass', { base: './src/css'})
.pipe(plumber())
.pipe(sass())
.pipe(autoprefixer({
browsers: ['last 3 versions'],
cascade: false
}))
.pipe(gulp.dest('./src/css'));
});
gulp.task('copy:example', function() {
return gulp.src('./build/*.js')
.pipe(gulp.dest('./example/phaser-inspector'));
});
gulp.task('watch', function() {
gulp.watch(['./src/css/**/*.sass'], ['css']);
})
function rebundle(bundler, debug) {
console.log('Start rebundling')
return bundler.bundle()
.on('error', function(err){
console.log(err)
})
.pipe(source('phaser-inspector.js'))
.pipe(gulp.dest('./build'))
.on('end', function(){
debug && runSequence('copy:example', function(){
console.log('REBUNDLED');
})
});
}
function bundle(debug){
watchify.args.debug = debug;
var bundler = browserify('./src/index.js', watchify.args);
debug && ( bundler = watchify(bundler) );
bundler.transform(stringify({ extensions: ['.html'] }));
bundler.transform(cssify);
bundler.transform( babelify.configure({ ignore : 'node_modules' }) );
(!debug) && bundler.transform('stripify');
debug && bundler.on('update', function(){
rebundle(bundler, debug);
});
return rebundle(bundler, debug);
}
gulp.task('browserify', function() {
return bundle(false);
});
gulp.task('browserify:debug', function() {
return bundle(true);
});
gulp.task('clean', function () {
return gulp.src([ './build/**/*.*', ], {read: false}).pipe(clean({force: true}));
});
gulp.task('default', function(cb) {
runSequence('css', 'clean', 'browserify', 'minify', 'copy:example', cb);
});
gulp.task('debug', function(cb) {
runSequence('watch', 'css', 'clean', 'browserify:debug', cb);
});