-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
81 lines (70 loc) · 1.69 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
const { src, dest, series, parallel } = require('gulp');
const INPUT_PATH = process.env.INPUT || `${__dirname}/export.zip`;
const BUILD_DIR = process.env.OUTPUT || `${__dirname}/build`;
const TMP_PATH = `${__dirname}/tmp`;
const GLOB = {
CSS: `${TMP_PATH}/css/**/*.css`,
JS: `${TMP_PATH}/js/**/*.js`,
HTML: `${TMP_PATH}/**/*.html`
};
const unzip = () => src(INPUT_PATH)
.pipe(require('gulp-unzip')())
.pipe(dest(TMP_PATH));
const cleanBuild = () => src(BUILD_DIR, { read: false, allowEmpty: true })
.pipe(require('gulp-clean')());
const cleanTmp = () => src(TMP_PATH, { read: false })
.pipe(require('gulp-clean')());
const css = () => {
const postcss = require('gulp-postcss');
return src(GLOB.CSS)
.pipe(postcss([
require('autoprefixer'),
require('cssnano'),
]))
.pipe(dest(`${BUILD_DIR}/css`));
}
const js = () => {
const uglify = require('gulp-uglify');
const strip = require('gulp-strip-comments');
return src(GLOB.JS)
.pipe(strip())
.pipe(uglify())
.pipe(dest(`${BUILD_DIR}/js`));
};
const html = () => {
const htmlmin = require('gulp-htmlmin');
return src(GLOB.HTML)
.pipe(htmlmin({
collapseWhitespace: true,
minifyCSS: true,
minifyJS: true,
removeComments: true
}))
.pipe(dest(BUILD_DIR));
};
const copy = () => {
const copy = require('gulp-copy');
const globs = [
`${TMP_PATH}/**/*.*`,
`!${GLOB.HTML}`,
`!${GLOB.JS}`,
`!${GLOB.CSS}`
];
return src(globs)
.pipe(copy(BUILD_DIR, { prefix: 1 }))
.pipe(dest(BUILD_DIR))
};
const optimize = series(
parallel(
cleanBuild,
unzip,
),
parallel(
css,
js,
html,
copy,
),
cleanTmp,
);
exports.default = optimize;