-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
120 lines (107 loc) · 3.04 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
const gulp = require("gulp"),
fileinclude = require("gulp-file-include"),
gulpIf = require("gulp-if"),
minify = require("gulp-minify"),
less = require("gulp-less"),
cleanCSS = require("gulp-clean-css"),
del = require("del"),
plumber = require("gulp-plumber"),
// imagemin = require("gulp-imagemin"),
// imageminAdvpng = require("imagemin-advpng"),
// imageminJpegRecompress = require("imagemin-jpeg-recompress"),
changed = require("gulp-changed"),
browserSync = require("browser-sync").create();
const PATHS = {
SRC: "./src",
DIST: "./dist",
HTML_EN: "./src/en/**/*.html",
HTML_ZH: "./src/zh/**/*.html",
HTML_EN_INCLUDE: "./src/includes/en/**/*.html",
HTML_ZH_INCLUDE: "./src/includes/zh/**/*.html",
JS: ["./src/data/*.js", "./src/js/*.js", "./src/lib/*.js"],
STYLE: "./src/style/*.less",
IMG: "./src/resource/**/@(*.png|*.PNG|*.jpg|*.jpeg|*.JPG|*.JPEG)",
OTHER_RES: "./src/resource/**/!(*.png|*.PNG|*.jpg|*.jpeg|*.JPG|*.JPEG)"
};
const ENV = process.env.NODE_ENV;
const isProd = (() => ENV === "production")();
gulp.task("clean", () => del(PATHS.DIST));
gulp.task("html_en", () => {
return gulp
.src(PATHS.HTML_EN, { base: PATHS.SRC })
.pipe(plumber())
.pipe(
fileinclude({
prefix: "@@",
basepath: "@file",
indent: true
})
)
.pipe(gulp.dest(PATHS.DIST))
.pipe(browserSync.stream());
});
gulp.task("html_zh", () => {
return gulp
.src(PATHS.HTML_ZH, { base: PATHS.SRC })
.pipe(plumber())
.pipe(
fileinclude({
prefix: "@@",
basepath: "@file",
indent: true
})
)
.pipe(gulp.dest(PATHS.DIST))
.pipe(browserSync.stream());
});
gulp.task("style", () => {
return gulp
.src(PATHS.STYLE)
.pipe(plumber())
.pipe(less())
.pipe(gulpIf(isProd, cleanCSS()))
.pipe(gulp.dest(`${PATHS.DIST}/css`))
.pipe(browserSync.stream());
});
gulp.task("js", () => {
return gulp
.src(PATHS.JS, { base: PATHS.SRC })
.pipe(plumber())
.pipe(gulpIf(isProd, minify()))
.pipe(gulp.dest(PATHS.DIST))
.pipe(browserSync.stream());
});
gulp.task("img", () => {
return gulp
.src(PATHS.IMG, { base: PATHS.SRC })
.pipe(plumber())
.pipe(changed(PATHS.DIST))
.pipe(gulp.dest(PATHS.DIST))
.pipe(browserSync.stream());
});
gulp.task("copy_other_res", () => {
return gulp
.src(PATHS.OTHER_RES, { base: PATHS.SRC })
.pipe(plumber())
.pipe(changed(PATHS.DIST))
.pipe(gulp.dest(PATHS.DIST))
.pipe(browserSync.stream());
});
gulp.task("build", ["clean"], () =>
gulp.start(["html_en", "html_zh", "style", "js", "img", "copy_other_res"])
);
gulp.task("dev_watch", ["build"], () => {
browserSync.init({
port: 8089,
server: {
baseDir: PATHS.DIST
},
startPath: `/zh`
});
gulp.watch([PATHS.HTML_EN, PATHS.HTML_EN_INCLUDE], ["html_en"]);
gulp.watch([PATHS.HTML_ZH, PATHS.HTML_ZH_INCLUDE], ["html_zh"]);
gulp.watch(PATHS.STYLE, ["style"]);
gulp.watch(PATHS.JS, ["js"]);
gulp.watch(PATHS.IMG, ["img"]);
gulp.watch(PATHS.OTHER_RES, ["copy_other_res"]);
});