forked from HispachanFiles/HispachanFiles
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
92 lines (79 loc) · 1.96 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');
var fs = require('fs');
var browserify = require('browserify');
var watchify = require('watchify');
var babelify = require('babelify');
var rimraf = require('rimraf');
var source = require('vinyl-source-stream');
var _ = require('lodash');
var browserSync = require('browser-sync');
var reload = browserSync.reload;
var nodemon = require('gulp-nodemon');
var buffer = require('vinyl-buffer');
var minify = require('gulp-minify');
var config = {
entryFile: './client/main.js',
outputDir: './public/dist/',
outputFile: 'app.js'
};
// clean the output directory
gulp.task('clean', function(cb){
rimraf(config.outputDir, cb);
});
var bundler;
function getBundler() {
if (!bundler) {
bundler = watchify(browserify(config.entryFile, _.extend({ debug: true }, watchify.args)));
}
return bundler;
};
function bundle() {
return getBundler()
.transform(babelify)
.bundle()
.on('error', function(err) { console.log('Error: ' + err.message); })
.pipe(source(config.outputFile))
.pipe(buffer())
.pipe(minify({
ext:{
src:'.js',
min:'.min.js'
}
}))
.pipe(gulp.dest(config.outputDir))
.pipe(reload({ stream: true }));
}
gulp.task('build-persistent', function() {
return bundle();
});
gulp.task('build', ['build-persistent'], function() {
process.exit(0);
});
gulp.task('nodemon', function (cb) {
var started = false;
return nodemon({
script: 'bin/www',
ignore: ["public/*", "data/*", "client/*", "*.jade"]
}).on('start', function () {
if (!started) {
cb();
started = true;
}
});
});
gulp.task('watch', ['build-persistent', 'nodemon'], function() {
browserSync.init(null, {
proxy: "http://localhost:8000",
port: 7000,
});
getBundler().on('update', function() {
gulp.start('build-persistent')
});
});
// WEB SERVER
gulp.task('serve', ['nodemon'], function () {
browserSync.init(null, {
proxy: "http://localhost:8000",
port: 7000,
});
});