-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
76 lines (65 loc) · 1.82 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
var gulp = require('gulp');
var nodemon = require('nodemon');
var browserify = require('browserify');
var watchify = require('watchify');
var babelify = require('babelify');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var gutil = require('gulp-util');
var watch = require('gulp-watch');
var uglify = require('gulp-uglify');
var sourcemaps = require('gulp-sourcemaps');
var chalk = require('chalk');
var bundler = browserify({
entries: ['./src/app/dash.jsx'],
extensions: ['.jsx'],
transform: [babelify],
debug: true,
cache: {},
packageCache: {}
});
function logger() {
var args = Array.prototype.slice.call(arguments);
return gutil.log.bind.apply(gutil.log, [gutil].concat(args));
}
function bundle() {
return bundler.bundle()
.on('error', logger(chalk.cyan('[browserify]')))
.pipe(source('dash.js'))
.pipe(buffer())
.pipe(sourcemaps.init({loadMaps: true}))
//.pipe(uglify())
.on('error',logger())
.pipe(sourcemaps.write())
.pipe(gulp.dest('./public'));
}
gulp.task('js', bundle);
gulp.task('static', function() {
return gulp.src('./src/www/**/*')
.pipe(gulp.dest('./public'));
});
gulp.task('build', ['js', 'static']);
gulp.task('watch-static', function() {
return gulp.src('./src/www/**/*')
.pipe(watch('./src/www/**/*'))
.pipe(gulp.dest('./public'));
});
gulp.task('watch-js', function() {
bundler.plugin(watchify)
.on('update', bundle)
.on('log', logger(chalk.magenta('[watchify]')));
return bundle();
});
gulp.task('watch', ['watch-static', 'watch-js']);
gulp.task('serve', function() {
nodemon({
script: './src/server/server.js',
ext: 'js json',
watch: './src/server',
verbose: true
})
.on('log', function(event) {
gutil.log(event.colour);
});
});
gulp.task('default', ['serve', 'watch']);