-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
138 lines (117 loc) · 2.66 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
133
134
135
136
137
138
/**
* Module Dependencies
*/
var gulp = require('gulp');
var jshint = require('gulp-jshint');
var browserSync = require('browser-sync');
var reload = browserSync.reload;
var nodemon = require('gulp-nodemon');
var connect = require('gulp-connect');
var uglify = require('gulp-uglify');
var minifyCSS = require('gulp-minify-css');
var clean = require('gulp-clean');
var concat = require('gulp-concat');
var runSequence = require('run-sequence');
/**
* Config
*/
var paths = {
styles: [
'./src/client/css/*.css',
],
scripts: [
'./src/client/js/*.js',
],
server: [
'./src/server/bin/www'
],
distServer: [
'./dist/server/bin/www'
]
};
var nodemonConfig = {
script: paths.server,
ext: 'html js css',
ignore: ['node_modules']
};
var nodemonDistConfig = {
script: paths.distServer,
ext: 'html js css',
ignore: ['node_modules']
};
/**
* Gulp Tasks
*/
gulp.task('lint', function() {
return gulp.src(paths.scripts)
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish'));
});
gulp.task('browser-sync', ['nodemon'], function(done) {
browserSync({
proxy: "localhost:3000", // local node app address
port: 5000, // use *different* port than above
notify: true
}, done);
});
gulp.task('nodemon', function (cb) {
var called = false;
return nodemon(nodemonConfig)
.on('start', function () {
if (!called) {
called = true;
cb();
}
})
.on('restart', function () {
setTimeout(function () {
reload({ stream: false });
}, 1000);
});
});
gulp.task('watch', function() {
gulp.watch(paths.scripts, ['lint']);
});
gulp.task('clean', function() {
gulp.src('./dist/*')
.pipe(clean({force: true}));
});
gulp.task('minify-css', function() {
var opts = {comments:true, spare:true};
gulp.src(paths.styles)
.pipe(minifyCSS(opts))
.pipe(gulp.dest('./dist/client/css/'));
});
gulp.task('minify-js', function() {
gulp.src(paths.scripts)
.pipe(uglify())
.pipe(gulp.dest('./dist/client/js/'));
});
gulp.task('copy-server-files', function () {
gulp.src('./src/server/**/*')
.pipe(gulp.dest('./dist/server/'));
});
gulp.task('connectDist', function (cb) {
var called = false;
return nodemon(nodemonDistConfig)
.on('start', function () {
if (!called) {
called = true;
cb();
}
})
.on('restart', function () {
setTimeout(function () {
reload({ stream: false });
}, 1000);
});
});
// *** default task *** //
gulp.task('default', ['browser-sync', 'watch'], function(){});
// *** build task *** //
gulp.task('build', function() {
runSequence(
['clean'],
['lint', 'minify-css', 'minify-js', 'copy-server-files', 'connectDist']
);
});