-
Notifications
You must be signed in to change notification settings - Fork 84
/
Copy pathgulpfile.js
85 lines (65 loc) · 1.67 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
const {series, src, dest} = require('gulp')
const rename = require('gulp-rename')
const sass = require('gulp-sass')(require('sass'))
const babel = require('gulp-babel')
const uglify = require('gulp-uglify')
/* Destination dir */
const destDir = './demo'
/* JS. Transpile with babel & minify */
const processJs = (baseName, isMin) => {
let r = src('src/js/' + baseName + '.js')
.pipe(babel({
presets: ['@babel/env']
}))
if (isMin) {
r = r.pipe(uglify()).pipe(rename(baseName + '.min.js'))
}
return r.pipe(dest(destDir + '/js'))
}
const processJsMain = () => {
return processJs('main')
}
const processJsMainMin = () => {
return processJs('main', true)
}
const processJsChartSample = () => {
return processJs('chart.sample')
}
const processJsChartSampleMin = () => {
return processJs('chart.sample', true)
}
/* SCSS */
const processScss = (baseName, isMin) => {
const outputStyle = isMin ? 'compressed' : 'expanded'
const destNameSuffix = isMin ? '.min' : ''
return src('src/scss/' + baseName + '.scss')
.pipe(sass({outputStyle}).on('error', sass.logError))
.pipe(rename(baseName + destNameSuffix + '.css'))
.pipe(dest(destDir + '/css'))
}
const processScssMain = () => {
return processScss('main')
}
const processScssMainMin = () => {
return processScss('main', true)
}
/* HTML */
const copyHtml = () => {
return src('src/html/*')
.pipe(dest(destDir))
}
/* Img */
const copyImg = () => {
return src('src/img/*')
.pipe(dest(destDir + '/img'))
}
exports.default = series(
processJsMain,
processJsMainMin,
processJsChartSample,
processJsChartSampleMin,
processScssMain,
processScssMainMin,
copyHtml,
copyImg
)