This repository has been archived by the owner on Feb 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
/
build.js
executable file
·96 lines (87 loc) · 2.7 KB
/
build.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
#!/usr/bin/env node
const { build, cliopts } = require('estrella')
const { readFileSync } = require('fs')
const path = require('path')
const builtIns = {
crypto: require.resolve('crypto-browserify'),
stream: require.resolve('stream-browserify'),
buffer: require.resolve('./node_modules/buffer/index.js')
}
const workerLoader = () => {
return {
name: 'worker-loader',
setup(plugin) {
plugin.onResolve({ filter: /(.+)-webworker(?:\.dev)?\.js$/ }, (args) => {
return { path: args.path, namespace: 'workerUrl' }
})
plugin.onLoad({ filter: /(.+)-webworker(?:\.dev)?\.js$/, namespace: 'workerUrl' }, async (args) => {
const dest = require.resolve(args.path)
return { contents: `export default ${JSON.stringify(readFileSync(dest).toString())};` }
})
}
}
}
const nodeBuiltIns = () => {
const include = Object.keys(builtIns)
if (!include.length) {
throw new Error('Must specify at least one built-in module')
}
const filter = RegExp(`^(${include.join('|')})$`)
return {
name: 'node-builtins',
setup(build) {
build.onResolve({ filter }, (arg) => ({
path: builtIns[arg.path]
}))
}
}
}
const commonOptions = {
bundle: true,
minify: !cliopts.watch,
sourcemap: cliopts.watch ? 'both' : undefined,
sourceRoot: path.resolve('./packages'),
sourcesContent: !!cliopts.watch,
treeShaking: true,
plugins: [nodeBuiltIns(), workerLoader()]
}
function createWorker(entry, outfile) {
return build({
...commonOptions,
entry,
outfile,
tsconfig: path.join(path.dirname(entry), 'tsconfig.json'),
inject: ['packages/entryPoints/inject.js']
})
}
if (!process.env.BUNDLES_ONLY) {
createWorker('packages/gif-processor/worker.ts', 'static/gif-processor/worker.js.txt')
createWorker('packages/voice-chat-codec/worker.ts', 'static/voice-chat-codec/worker.js.txt')
createWorker(
'packages/voice-chat-codec/audioWorkletProcessors.ts',
'static/voice-chat-codec/audioWorkletProcessors.js.txt'
)
createWorker('packages/ui/decentraland-ui.scene.ts', 'static/systems/decentraland-ui.scene.js.txt')
}
if (!process.env.ESSENTIALS_ONLY) {
build({
...commonOptions,
entry: 'packages/entryPoints/index.ts',
outfile: 'static/index.js',
tsconfig: 'packages/entryPoints/tsconfig.json',
inject: ['packages/entryPoints/inject.js']
})
build({
...commonOptions,
debug: true,
clear: true,
minify: false,
sourcemap: 'both',
entry: 'test/index.ts',
outfile: 'test/out/index.js',
tsconfig: 'test/tsconfig.json',
inject: ['packages/entryPoints/inject.js']
})
}
// Run a local web server with livereload when -watch is set
cliopts.watch && require('./scripts/runTestServer')