-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.js
More file actions
60 lines (58 loc) · 1.47 KB
/
build.js
File metadata and controls
60 lines (58 loc) · 1.47 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
const esbuild = require('esbuild')
const path = require('path')
const glob = require('glob')
const chalk = require('chalk')
const fs = require('fs-extra')
const isProd = process.env.NODE_ENV == 'production'
const libPath = path.join(process.cwd(), 'lib')
const copyStaticFiles = require('esbuild-copy-static-files')
/** 假如lib文件夹已存在,则清空 */
if (fs.existsSync(libPath)) {
fs.emptyDirSync(libPath)
}
/** 匹配src文件夹下所有ts文件 */
const matchFiles = async () => {
return await new Promise((resolve) => {
glob('src/**/*.ts', { root: process.cwd() }, function (err, files) {
if (err) {
console.error(err)
process.exit(1)
}
resolve(files)
})
})
}
/** esbuild 配置 */
const build = async function () {
await esbuild.build({
entryPoints: await matchFiles(),
bundle: false,
splitting: false,
outdir: path.join(process.cwd(), 'lib'),
format: 'cjs',
platform: 'node',
minify: false,
color: true,
sourcemap: false,
loader: {
".ts": 'ts'
},
plugins: [
copyStaticFiles({
src: './src/template',
dest: './lib/template',
})
],
watch: !isProd && {
onRebuild(error) {
if (error) {
console.log(chalk.red.bold(`🟥 Watch Build Failed`))
} else {
console.log(chalk.blue.bold(`🟦 Watch Build Succeeded`))
}
},
},
})
console.log(chalk.green.bold('🟩 Success Build \r\n'))
}
build()