-
Notifications
You must be signed in to change notification settings - Fork 26
/
build.js
executable file
·25 lines (18 loc) · 696 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
const fs = require('fs');
const terser = require('terser');
const MINIFY = true;
try { fs.mkdirSync('./dist'); }
catch (e) {}
const wasmBuffer = fs.readFileSync('./lib/lexer.wasm');
const jsSource = fs.readFileSync('./src/lexer.js').toString();
const pjson = JSON.parse(fs.readFileSync('./package.json').toString());
const jsSourceProcessed = jsSource.replace('WASM_BINARY', wasmBuffer.toString('base64'));
const minified = MINIFY && terser.minify(jsSourceProcessed, {
module: true,
output: {
preamble: `/* cjs-module-lexer ${pjson.version} */`
}
});
if (minified.error)
throw minified.error;
fs.writeFileSync('./dist/lexer.mjs', minified ? minified.code : jsSourceProcessed);