-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathesbuild.config.ts
58 lines (51 loc) · 1.3 KB
/
esbuild.config.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
import minimist from 'minimist'
import esbuild from 'esbuild'
import glob from 'glob'
import { clean } from 'esbuild-plugin-clean'
import type { BuildOptions } from 'esbuild'
const args = minimist(process.argv.splice(2))
const watch = args.watch as boolean
const baseOptions: BuildOptions = {
watch: watch
? {
onRebuild(error, result) {
if (error) console.error('watch build failed:', error)
else console.log('watch build succeeded:', result)
},
}
: false,
// entryPoints: ['./packages/create-app/index.js', './packages/lv/index.js'],
bundle: true,
platform: 'node',
target: 'node16',
external: ['@lvjiaxuan/create-app', '@lvjiaxuan/lv'],
}
const getConfigByPath = (path: string) => {
const entryPoints = [path + 'index.js']
path.includes('create-app') && entryPoints.push(path + 'create.js')
return {
entryPoints,
outdir: path + 'dist',
plugins: [
clean({
patterns: [path + 'dist'],
}),
],
}
}
const packages = glob.sync('packages/*/') as string[]
packages.forEach(path => {
// cjs
esbuild.build({
...baseOptions,
...getConfigByPath(path),
})
// esm
esbuild.build({
...baseOptions,
...getConfigByPath(path),
splitting: true,
format: 'esm',
outExtension: { '.js': '.mjs' },
})
})