-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathgulpfile.js
More file actions
67 lines (59 loc) · 1.44 KB
/
gulpfile.js
File metadata and controls
67 lines (59 loc) · 1.44 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/**
* @Author: Caven Chen
* @Date: 2024-04-26
*/
'use strict'
import fse from 'fs-extra'
import path from 'path'
import gulp from 'gulp'
import tsup from 'tsup'
import shell from 'shelljs'
import chalk from 'chalk'
const buildConfig = {
entryPoints: ['src/index.ts'],
dts: true,
target: `es2022`,
minify: false,
sourcemap: false,
external: ['three'],
splitting: false,
}
async function buildModules(options = {}) {
await tsup.build({
...buildConfig,
format: 'esm',
minify: options.minify,
esbuildOptions: (options, context) => {
delete options.outdir
options.outfile = path.join('dist', 'index.js')
},
})
}
async function regenerate(option, content) {
await fse.remove('dist/index.js')
await buildModules(option)
}
export const dev = gulp.series(() => {
shell.echo(chalk.yellow('============= start dev =============='))
const watcher = gulp.watch('src', {
persistent: true,
awaitWriteFinish: {
stabilityThreshold: 1000,
pollInterval: 100,
},
})
watcher
.on('ready', async () => {
await regenerate()
})
.on('change', async () => {
let now = new Date().getTime()
await regenerate()
shell.echo(
chalk.green(`regenerate lib takes ${new Date().getTime() - now} ms`)
)
})
return watcher
})
export const build = gulp.series(() => buildModules())
export const buildRelease = gulp.series(() => buildModules({ minify: true }))