This repository has been archived by the owner on Feb 6, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathesbuild.js
67 lines (58 loc) · 1.63 KB
/
esbuild.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
const esbuild = require('esbuild');
const {readFile, writeFile} = require('fs').promises;
const minify = require('html-minifier-terser').minify;
// sandbox
esbuild
.build({
entryPoints: ['src/plugin.ts'],
bundle: true,
platform: 'node',
target: ['node10.4'],
outfile: 'dist/plugin.js'
})
.catch(() => process.exit(1));
// iframe UI
const buildWebComponents = (entryPoints) =>
entryPoints
.map((entryPoint) =>
esbuild.buildSync({
entryPoints: [entryPoint],
bundle: true,
minify: true,
write: false,
target: ['chrome58', 'firefox57', 'safari11', 'edge16'],
format: 'esm'
})
)
.map((componentScript) => componentScript.outputFiles[0].text)
.join('');
(async () => {
const script = esbuild.buildSync({
entryPoints: ['src/ui.ts'],
bundle: true,
minify: true,
write: false,
target: ['chrome58', 'firefox57', 'safari11', 'edge18']
});
const componentsScript = buildWebComponents([
'src/components/checkbox.ts',
'src/components/button.ts',
'src/components/spinner.ts',
'src/components/fonts.ts'
]);
const html = await readFile('src/ui.html', 'utf8');
const minifyOptions = {
collapseWhitespace: true,
keepClosingSlash: true,
removeComments: true,
removeRedundantAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
useShortDoctype: true,
minifyCSS: true
};
await writeFile(
'dist/ui.html',
`<script>${script.outputFiles[0].text}</script><script type="module">${componentsScript}</script>${await minify(html, minifyOptions)}`
);
})();