-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathbuild-function.js
More file actions
47 lines (41 loc) · 1.11 KB
/
build-function.js
File metadata and controls
47 lines (41 loc) · 1.11 KB
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
#!/usr/bin/env node
'use strict';
import { build } from 'esbuild';
import fs from 'fs/promises';
import { join } from 'path';
import { nodeModulesPolyfillPlugin } from 'esbuild-plugins-node-modules-polyfill';
const html = (contents) => `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>browserless.io function runner</title>
<script type="module">
${contents}
</script>
</head>
<body>
</body>
</html>
`;
const entryPoints = ['src/shared/utils/function/client.ts'];
const outfile = join(process.cwd(), 'static/function/client.js');
const htmlLocation = join(process.cwd(), 'static/function/index.html');
(async () => {
await build({
bundle: true,
entryPoints,
outfile,
plugins: [
nodeModulesPolyfillPlugin({
globals: {
process: false,
},
}),
],
});
const contents = await fs.readFile(outfile, 'utf-8');
const final = html(contents);
await fs.writeFile(htmlLocation, final);
})();