-
Notifications
You must be signed in to change notification settings - Fork 0
/
bundle.ts
35 lines (28 loc) · 965 Bytes
/
bundle.ts
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
import { bundle } from 'jsr:@deno/[email protected]';
import { copy, emptyDir } from 'jsr:@std/[email protected]';
async function bundleFile(sourcePath: string | URL, outputPath: string | URL) {
const result = await bundle(sourcePath, {
'minify': true,
});
await Deno.writeTextFile(outputPath, result.code);
}
async function main() {
// Get directory URLs
const sourceDir = new URL('./source/', import.meta.url);
const distDir = new URL('./dist/', import.meta.url);
const publicDir = new URL('./public/', import.meta.url);
// Define the source files to bundle
const sourceFiles = ['contentscript.ts'];
// Clear the contents of the dist directory
await emptyDir(distDir);
// Bundle TypeScript files
for (const file of sourceFiles) {
await bundleFile(
new URL(file, sourceDir),
new URL(file.replace(/\.ts$/, '.js'), distDir),
);
}
// Copy the contents of the public directory to dist
await copy(publicDir, distDir, { overwrite: true });
}
main();