forked from ateliee/jquery.schedule
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
94 lines (90 loc) · 2.47 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
let gulp = require('gulp');
let uglify = require('gulp-uglify');
let sourcemaps = require('gulp-sourcemaps');
let rename = require('gulp-rename');
let plumber = require('gulp-plumber');
let shell = require('gulp-shell');
let sass = require('gulp-sass')(require('sass'));
let browserSync = require('browser-sync');
let tagVersion = require('gulp-tag-version');
let babel = require('gulp-babel');
// js minify
gulp.task('js-minify', function () {
return gulp.src(['./dist/**/*.js', '!./dist/**/*.min.js'])
.pipe(plumber())
.pipe(sourcemaps.init())
.pipe(uglify())
.pipe(rename({ suffix: '.min' }))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('./dist/'));
});
// dist clean
gulp.task('clean-dist', shell.task('rm -rf dist/*'));
// compile
gulp.task('compile', function() {
return gulp.src('src/**/*.js')
.pipe(babel({
presets: ['@babel/preset-env']
}))
.pipe(gulp.dest('dist'));
});
// sass compile
gulp.task('sass-minify', function () {
return gulp.src('./src/sass/**/*.scss')
.pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError))
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest('./dist/css'));
});
gulp.task('sass', function () {
return gulp.src('./src/sass/**/*.scss')
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest('./dist/css'));
});
// build
gulp.task('build', gulp.series(
'clean-dist',
gulp.parallel(
'compile',
'sass'
),
gulp.parallel(
'js-minify',
'sass-minify'
)
));
gulp.task('tag', function() {
return gulp.src(['./package.json']).pipe(tagVersion());
});
// Static server
gulp.task('browser-sync', function() {
return browserSync.init({
server: {
baseDir: ".",
},
open: false,
// browser: 'google chrome',
startPath: 'demo/index.html'
});
});
gulp.task('bs-reload', function (done) {
browserSync.reload();
done();
});
// Watch scss AND html files, doing different things with each.
gulp.task('watch', function (done) {
gulp.watch("./src/sass/*.scss", gulp.series(
'sass-minify',
'bs-reload'
));
gulp.watch("./src/js/*.js", gulp.series(
'compile',
'js-minify',
'bs-reload'
));
gulp.watch("./demo/*", gulp.series(
'bs-reload'
));
done();
});
gulp.task('serve', gulp.series('build', 'watch', 'browser-sync'));
gulp.task('default', gulp.task('serve'));