-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.babel.js
More file actions
106 lines (89 loc) · 2.4 KB
/
gulpfile.babel.js
File metadata and controls
106 lines (89 loc) · 2.4 KB
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
/**
* Web Starter Kit
*/
'use strict';
// This gulpfile makes use of new JavaScript features.
// Babel handles this without us having to do anything. It just works.
// You can read more about the new JavaScript features here:
// https://babeljs.io/docs/learn-es2015/
import gulp from 'gulp';
import gulpLoadPlugins from 'gulp-load-plugins';
import browserSync from 'browser-sync';
import rimraf from 'rimraf';
const $ = gulpLoadPlugins();
// const reload = browserSync.reload;
// 输出目录
const dist = 'dest';
const PRODUCTION = false;
// build任务:先调用clean,在并行调用javascript、images
gulp.task('build',
gulp.series(clean, gulp.parallel(javascript, images)));
gulp.task('default',
gulp.series('build'));
gulp.task('dev',
gulp.series('build', devServer, watch));
gulp.task('demo',
gulp.series('build', demoServer));
// Reload the browser with BrowserSync
function reload(done) {
browserSync.reload();
done();
}
// Watch for changes to static assets, pages, Sass, and JavaScript
function watch() {
gulp.watch("src/**/*.js").on('change', gulp.series(javascript, reload));
gulp.watch("test/**/*").on('change', gulp.series(javascript, reload));
}
// 清空dist目录
function clean(done) {
// del(['.tmp', 'dist/*', '!dist/.git'], {dot: true});
rimraf(dist, done);
}
// 暂时未使用
function css() {
// do nothing
}
// 合并压缩js
// 若PRODUCTION为true就混淆js
function javascript() {
return gulp.src("src/**/*.js")
.pipe($.sourcemaps.init())
.pipe($.babel())
// .pipe($.concat('app.js'))
.pipe($.if(PRODUCTION, $.uglify().on('error', e => { console.log(e); })))
.pipe(gulp.dest(dist + '/js'));
}
// copy 图片到输出目录,若PRODUCTION则压缩图片
function images() {
return gulp.src("src/images/**/*")
// .pipe($.if(PRODUCTION, $.imagemin({
// progressive: true
// })))
.pipe(gulp.dest(dist + "/images"));
}
// 暂时未使用
function copy() {
// do nothing
}
// Start a server with BrowserSync to preview the site in
function devServer(done) {
browserSync.init({
server: {
baseDir: [dist, "test"],
index: 'SpecRunner.html'
},
port: 8888
});
done();
}
// Start a server with BrowserSync to preview the site in
function demoServer(done) {
browserSync.init({
server: {
baseDir: [dist, "demo"],
index: 'main.html'
},
port: 8888
});
done();
}