-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathgulpfile.js
68 lines (56 loc) · 1.32 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
import gulp from 'gulp';
import { deleteAsync } from 'del';
import terser from 'gulp-terser';
import prettyData from 'gulp-pretty-data';
const src = './src'
const globalPaths = {
js: [`${src}/**/*.js`],
wxml: [`${src}/**/*.wxml`],
wxss: [`${src}/**/*.wxss`],
json: [`${src}/**/*.json`],
}
const BUILD_PATH = {
dist: './miniprogram_dist',
example: './example/wx-drag-img'
}
// 编译输出路径
let buildPath = BUILD_PATH.dist
/**
* 切换编译输出路径
* @param {*} path
*/
const toggleBuildPath = async () => {
buildPath = BUILD_PATH.example
}
const clear = async () => await deleteAsync(buildPath);
const js = () => gulp
.src(globalPaths.js)
.pipe(terser())
.pipe(gulp.dest(buildPath))
const wxss = () => gulp
.src(globalPaths.wxss)
.pipe(prettyData({
type: 'minify',
extensions: {
wxss: 'css',
},
}))
.pipe(gulp.dest(buildPath))
const wxml = () => gulp
.src(globalPaths.wxml)
.pipe(prettyData({
type: 'minify',
extensions: {
wxml: 'xml',
},
}))
.pipe(gulp.dest(buildPath))
const json = () => gulp
.src(globalPaths.json)
.pipe(prettyData({
type: 'minify',
preserveComments: true,
}))
.pipe(gulp.dest(buildPath))
export const example = gulp.series(toggleBuildPath, clear, gulp.parallel(js, wxss, wxml, json))
export const build = gulp.series(clear, gulp.parallel(js, wxss, wxml, json))