-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathesbuild.config.js
110 lines (100 loc) · 2.83 KB
/
esbuild.config.js
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#! node
const esbuild = require('esbuild')
const argv = require('minimist')(process.argv.slice(2))
const { rimraf } = require('rimraf')
const { copy } = require('esbuild-plugin-copy')
const { join } = require('path')
const package = require('./package.json')
const APP_VERSION = package.version
const TEST_PROD = false // do not commit this as true. Its just for testing prod builds locally
const minify = argv['minify'] ?? false
const watch = argv['watch'] ?? false
const isProd = TEST_PROD || minify === true
const sharedConfig = {
logLevel: 'info',
bundle: true,
outdir: 'dist',
sourcemap: true,
minify,
banner: {
js: `const environment = ${isProd ? "'prod'" : "'dev'"}; const APP_VERSION = '${APP_VERSION}';`,
},
external: ['vscode'], //Object.keys(require('../package.json').dependencies),
}
const extensionConfig = {
...sharedConfig,
entryPoints: [
{
out: 'main',
in: './src/client/extension.ts',
},
{
out: 'server',
in: './src/server/server.ts',
},
],
platform: 'node',
format: 'cjs',
// target: 'node12',
plugins: [
copyAssets(['assets', '**', '*'], ['dist', 'webview']),
copyAssets(
['node_modules', '@vscode', 'codicons', 'dist', 'codicon.css'],
['dist', 'webview', 'css'],
),
copyAssets(
['node_modules', '@vscode', 'codicons', 'dist', 'codicon.ttf'],
['dist', 'webview', 'css'],
),
],
}
const webConfig = {
...sharedConfig,
outdir: 'dist/webview',
entryPoints: [
{
out: 'main',
in: './src/scripts/index.ts',
},
],
platform: 'browser',
format: 'iife',
plugins: [copyJsBeebAssets('roms'), copyJsBeebAssets('sounds')],
}
function copyJsBeebAssets(dir) {
return copyAssets(
['node_modules', 'jsbeeb', dir, '**', '*'],
['dist', 'webview', 'jsbeeb', dir],
)
}
function copyAssets(src, dst) {
// const from = join('node_modules', 'jsbeeb', dir, '**', '*');
// const to = join('dist', 'assets', 'jsbeeb', dir);
const from = join(...src)
const to = join(...dst)
console.log(`assets will be copied from '${from}' to '${to}'`)
return copy({
// this is equal to process.cwd(), which means we use cwd path as base path to resolve `to` path
// if not specified, this plugin uses ESBuild.build outdir/outfile options as base path.
resolveFrom: 'cwd',
assets: {
from: [from],
to: [to],
},
watch,
verbose: false,
})
}
async function main() {
console.log('cleaning...')
await rimraf(sharedConfig.outdir)
console.log('building...')
await Promise.all([esbuild.build(extensionConfig), esbuild.build(webConfig)])
if (watch) {
console.log('watching...')
const extensionContext = await esbuild.context(extensionConfig)
const webContext = await esbuild.context(webConfig)
await Promise.all([extensionContext.watch(), webContext.watch()])
}
}
main()