forked from mickidum/acc_toolbar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
111 lines (96 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
var gulp = require('gulp'),
gutil = require('gulp-util' ),
gulpSass = require('gulp-sass'),
browserSync = require('browser-sync'),
concat = require('gulp-concat'),
uglify = require('gulp-uglify'),
cleanCSS = require('gulp-clean-css'),
rename = require('gulp-rename'),
cache = require('gulp-cache'),
autoprefixer = require('gulp-autoprefixer'),
notify = require("gulp-notify"),
fileinclude = require('gulp-file-include'),
htmlmin = require('gulp-htmlmin'),
rimraf = require("rimraf");
function minifyHtml(cb) {
gulp.src('app/htmlparts/**/*.html')
.pipe(htmlmin({collapseWhitespace: true}))
.pipe(gulp.dest('app/htmlmin'))
setTimeout(() => cb(), 100);
}
function commonJs(cb) {
gulp.src([
'app/js/**/*.js',
])
.pipe(fileinclude({
prefix: '@@',
basepath: '@file'
}))
.pipe(rename({suffix: '.min', prefix : ''}))
.pipe(uglify())
.pipe(gulp.dest('app/minjs'))
.pipe(browserSync.stream());
cb();
}
function browser(cb) {
browserSync({
server: {
baseDir: 'app'
},
open: false,
notify: false,
});
cb();
}
function code(cb) {
gulp.src('app/*.html')
.pipe(browserSync.stream());
cb();
}
function sass(cb) {
gulp.src('app/scss/**/*.scss')
.pipe(gulpSass({
outputStyle: 'expand'}).on("error", notify.onError()))
.pipe(rename({suffix: '.min', prefix : ''}))
.pipe(autoprefixer(['last 2 versions']))
.pipe(cleanCSS()) // comment on debug
.pipe(gulp.dest('app/css'))
setTimeout(() => cb(), 100);
}
function files(cb) {
setTimeout(() => {
gulp.src([
'app/minjs/common.min.js'
])
.pipe(rename('acctoolbar.min.js'))
.pipe(gulp.dest('acctoolbar'));
gulp.src([
'app/cursors/**/*',
]).pipe(gulp.dest('acctoolbar/cursors'));
cb();
}, 500);
}
function remDist(cb) {
rimraf('acctoolbar', cb);
}
function clearCache (cb) {
cache.clearAll();
cb();
}
function watch(cb) {
gulp.watch('app/scss/**/*.scss', gulp.series(sass, commonJs));
gulp.watch('app/htmlparts/**/*.html', gulp.series(minifyHtml, commonJs));
gulp.watch('app/js/**/*.js', gulp.parallel(commonJs));
gulp.watch('app/*.html', gulp.parallel(code));
cb();
}
// exports.build = gulp.series(remDist, minifyHtml, sass, commonJs, files);
exports.build = gulp.series(remDist, minifyHtml, sass, commonJs, files);
exports.clearcache = gulp.parallel(clearCache);
exports.rem = gulp.parallel(remDist);
exports.buildhtml = gulp.parallel(minifyHtml);
exports.buildcss = gulp.parallel(sass);
exports.buildjs = gulp.parallel(commonJs);
exports.buildfiles = gulp.parallel(files);
exports.default = gulp.parallel(watch, browser);
// exports.build = gulp.parallel(buildall);