gulpfile.js
1.2 KB
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
const gulp = require('gulp')
const rename = require('gulp-rename')
const less = require('gulp-less')
const ts = require('gulp-typescript')
const dist = 'miniprogram_dist'
const demoDir = 'demo'
const lessFiles = ['./src/index.less']
const tsFiles = ['./src/*.ts']
const tsProject = ts.createProject('tsconfig.json')
function buildts() {
return gulp.src(tsFiles)
.pipe(tsProject())
.pipe(gulp.dest(dist))
}
function buildless() {
return gulp.src(lessFiles)
.pipe(less())
.pipe(rename({extname: '.wxss'}))
.pipe(gulp.dest(dist))
}
function cp() {
return gulp.src([
'./src/index.json',
'./src/index.wxml'
]).pipe(gulp.dest(dist))
}
function demo() {
return gulp.src(`${dist}/**/*`).pipe(gulp.dest(`${demoDir}/components`))
}
function watchless() {
return gulp.watch(lessFiles, gulp.series(buildless, cp, demo))
}
function watchts() {
return gulp.watch(tsFiles, gulp.series(buildts, cp, demo))
}
function watch() {
return gulp.watch([
'src/**/*',
...[...lessFiles, ...tsFiles].map(v => `!${v}`)
], gulp.series(cp, demo))
}
exports.build = gulp.series(gulp.parallel(buildless, buildts), cp, demo)
exports.default = gulp.parallel(exports.build, watch, watchless, watchts)