-
Notifications
You must be signed in to change notification settings - Fork 105
/
Copy pathbuild.ts
74 lines (70 loc) · 2.13 KB
/
build.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
const { build } = require("esbuild")
const { resolve } = require("path")
const { existsSync } = require("fs")
const { copy } = require("esbuild-plugin-copy")
const isProd = process.argv.indexOf('--mode=production') >= 0;
const dependencies = ['vscode-html-to-docx', 'highlight.js', 'pdf-lib', 'cheerio', 'katex', 'mustache', 'puppeteer-core']
function main() {
build({
entryPoints: ['./src/extension.ts'],
bundle: true,
outfile: "out/extension.js",
external: ['vscode', ...dependencies],
format: 'cjs',
platform: 'node',
// logLevel: 'error',
metafile: true,
// sourceRoot: __dirname+"/src",
minify: isProd,
watch: !isProd,
sourcemap: !isProd,
logOverride: {
'duplicate-object-key': "silent",
'suspicious-boolean-not': "silent",
},
plugins: [
// 复制生成pdf的静态文件
copy({
resolveFrom: 'out',
assets: {
from: ['./template/**/*'],
to: ['./'],
keepStructure: true
},
}),
{
name: 'build notice',
setup(build) {
build.onStart(() => {
console.log('build start')
})
build.onEnd(() => {
console.log('build success')
})
}
},
],
})
}
function createLib() {
const points = dependencies.reduce((point, dependency) => {
const main = require(`./node_modules/${dependency}/package.json`).main ?? "index.js";
const mainAbsPath = resolve(`./node_modules/${dependency}`, main);
if (existsSync(mainAbsPath)) {
point[dependency] = mainAbsPath;
}
return point;
}, {})
build({
entryPoints: points,
bundle: true,
outdir: "out/node_modules",
format: 'cjs',
platform: 'node',
minify: true,
treeShaking: true,
metafile: true
})
}
createLib();
main();