-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
64 lines (57 loc) · 1.44 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
/**
* @file gulp入口文件
* @author hejiangtao
* @desc 自动化入口文件
*/
const { src, watch, dest, series, parallel } = require('gulp');
// 将 gulp 插件引入简洁化
const gulpLoadPlugins = require('gulp-load-plugins');
const g = gulpLoadPlugins();
// 小程序的所有文件放在 src 里面
const root = 'src/';
// 使用 ts 代替 js 开发
const ts = [`${root}**/*.ts`];
// 使用 less 编写样式,最后转译成 wxss
const less = [`${root}**/*.less`];
// 集中不需要处理的文件目录
const copyFile = [
`${root}**/*.json`,
`${root}**/*.wxml`,
`${root}**/*.wxss`,
`${root}**/*.js`,
`${root}**/*.png`,
`${root}**/*.svg`,
`${root}**/*.jpg`,
`${root}**/*.gif`,
];
// 处理一些无需编译的文件
function copyOtherFile() {
return src(copyFile)
.pipe(g.cached('copyFile'))
.pipe(dest('dist/'));
}
// less 转 css 生成 wxss
function transformLess() {
return src(less)
.pipe(g.less())
.pipe(g.rename({
extname: '.wxss'
}))
.pipe(dest('dist/'));
}
function ts2js() {
return src(ts)
.pipe(g.cached('tsFile'))
.pipe(g.typescript({
target: 'es5'
}))
.pipe(dest('dist/'));
}
exports.build = async () => {
const wathOpts = {
ignoreInitial: false
};
watch(ts, wathOpts, ts2js);
watch(less, wathOpts, transformLess);
watch(copyFile, wathOpts, copyOtherFile);
}