-
Notifications
You must be signed in to change notification settings - Fork 61
/
gulpfile.ts
95 lines (80 loc) · 2.29 KB
/
gulpfile.ts
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
86
87
88
89
90
91
92
93
94
95
import gulp from 'gulp'
import clean from 'gulp-clean'
import tsc from 'gulp-typescript'
import path from 'path'
import swc from 'gulp-swc'
import esbuild from 'gulp-esbuild'
import watch from 'gulp-watch'
import config from './config'
const {
srcPath,
esbuildOptions,
swcOptions,
bundleInDemoPath,
bundlePath,
typesPath,
tsConfigPath,
swcBuildPath,
entry,
} = config
const genTsc = () => {
return tsc.createProject(tsConfigPath)
}
gulp.task('clean-dev-bundle', () => {
return gulp.src(bundleInDemoPath, { allowEmpty: true }).pipe(clean())
})
gulp.task('clean-demo-dev-bundle', () => {
return gulp.src(bundleInDemoPath, { allowEmpty: true }).pipe(clean())
})
gulp.task('clean-bundle', () => {
return gulp.src(bundlePath, { allowEmpty: true }).pipe(clean())
})
gulp.task('clean-dts', () => {
return gulp.src(typesPath, { allowEmpty: true }).pipe(clean())
})
gulp.task('gen-dts', () => {
const tsc = genTsc()
return tsc.src().pipe(tsc()).pipe(gulp.dest(typesPath))
})
gulp.task('swc-ts-2-js', () => {
return gulp.src(path.resolve(srcPath, '*.ts')).pipe(swc(swcOptions)).pipe(gulp.dest(swcBuildPath))
})
gulp.task('esbuild-bundle', () => {
return gulp
.src(path.resolve(swcBuildPath, `${entry}.js`))
.pipe(esbuild(esbuildOptions))
.pipe(gulp.dest(bundlePath))
})
gulp.task('esbuild-bundle-dev', () => {
return gulp
.src(path.resolve(swcBuildPath, `${entry}.js`))
.pipe(esbuild({ ...esbuildOptions, minify: false, outfile: 'index.dev.js' }))
.pipe(gulp.dest(bundlePath))
})
gulp.task('copy-2-demo', () => {
return gulp.src(path.resolve(swcBuildPath, '*.js')).pipe(gulp.dest(bundleInDemoPath))
})
gulp.task('watch', () => {
const tsFile = path.resolve(srcPath, '*.ts')
const watcher = watch(tsFile, gulp.series('dev'))
watcher.on('change', function (path, stats) {
console.log(`File ${path} was changed`)
})
})
// build for develop
gulp.task(
'dev',
gulp.series(
'clean-dev-bundle',
'clean-demo-dev-bundle',
'swc-ts-2-js',
'esbuild-bundle-dev',
'copy-2-demo',
),
)
// build for develop & watch
gulp.task('dev-watch', gulp.series('dev', 'watch'))
// generate .d.ts
gulp.task('dts', gulp.series('clean-dts', 'gen-dts'))
// build for publish
gulp.task('default', gulp.series('clean-bundle', 'swc-ts-2-js', 'esbuild-bundle', 'dts'))