-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
116 lines (96 loc) · 2.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
var gulp = require('gulp');
var browserSync = require('browser-sync').create();
var cleanCss = require('gulp-clean-css');
var uglify = require('gulp-uglify');
var pump = require('pump');
var minimist = require('minimist');
var del = require('del');
var knownOptions = {
string: 'mode',
default: {mode: 'simple'}
};
var options = minimist(process.argv.slice(2), knownOptions);
var appDevRoot = options.mode;
function minifyJs(callback) {
pump([
gulp.src('./src/scripts/*'),
uglify(),
gulp.dest('./dist/scripts')
],
callback
);
}
function copyModules() {
return gulp.src('./src/modules/**/*')
.pipe(gulp.dest('./dist/scripts/vendor'))
}
function copyVendorJs() {
return gulp.src('./src/scripts/vendor/**/*')
.pipe(gulp.dest('./dist/scripts/vendor'))
}
function minifyCss() {
return gulp.src(['./src/styles/**/*'])
.pipe(cleanCss())
.pipe(gulp.dest('./dist/styles'))
}
function copyImages() {
return gulp.src('./src/images/**/*')
.pipe(gulp.dest('./dist/images'));
}
function copyRootFiles() {
return gulp.src('./src/app/' + appDevRoot + '/**/*')
.pipe(gulp.dest('./dist'));
}
function startBrowserSync() {
// wait one second to initialize browser-sync.
setTimeout(function () {
browserSync.init({
server: './dist'
});
}, 2000);
}
function build(callback) {
minifyCss();
copyVendorJs();
copyModules();
copyRootFiles();
copyImages();
minifyJs(function (err) {
if (err) {
console.log(err);
return;
}
callback();
});
}
gulp.task('watch:cssmin', function () {
minifyCss()
.pipe(browserSync.stream());
});
gulp.task('watch:jsmin', function () {
minifyJs(function (err) {
if (err) {
console.log(err);
return;
}
browserSync.reload();
});
});
gulp.task('watch:copy', function () {
copyRootFiles()
.pipe(browserSync.stream());
});
gulp.task('clean', function () {
return Promise.all([
del('./dist')
]);
});
gulp.task('build', ['clean'], function (done) {
return build(done);
});
gulp.task('default', ['build'], function () {
startBrowserSync();
gulp.watch('./src/scripts/**/*', ['watch:jsmin']);
gulp.watch('./src/styles/**/*', ['watch:cssmin']);
gulp.watch('./src/app/' + appDevRoot + '/**/*', ['watch:copy']);
});