-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
34 lines (29 loc) · 980 Bytes
/
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
const { build } = require('esbuild');
const { promises } = require('fs');
const { bundle } = require('luabundle');
(async function () {
const jsOutfile = 'gmod-webaudio.min.js';
const luaOutfile = 'src/lua/browserjs.lua';
const result = await build({
entryPoints: ['src/js/index.js'],
bundle: true,
minify: true,
platform: 'browser',
target: 'chrome18',
/* i wish there was a way to output the bundle directly to
the result object */
outfile: jsOutfile
});
if (result.errors.length !== 0) {
console.error(result.errors);
return process.exit(1);
}
if (result.warnings.length !== 0)
console.warn(result.warnings);
const file = await promises.readFile(jsOutfile);
await promises.rm(jsOutfile);
await promises.writeFile(luaOutfile, 'local a = [==[' + file + ']==] return a');
const bundled = await bundle('src/lua/main.lua', { paths: ['src/lua/?.lua'] });
await promises.rm(luaOutfile);
await promises.writeFile('bundle.lua', bundled);
})();