-
Notifications
You must be signed in to change notification settings - Fork 0
/
deno-build-typescript.ts
75 lines (66 loc) · 2.01 KB
/
deno-build-typescript.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
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
68
69
70
71
72
73
74
75
import * as esbuild from "npm:esbuild";
import { solidPlugin } from "npm:esbuild-plugin-solid";
import { denoPlugins } from "https://cdn.jsdelivr.net/gh/Ciantic/esbuild_deno_loader/mod.ts";
async function buildTsFile(file: string, outFile: string) {
if (!file) {
console.error("Please provide a file to bundle.");
return false;
}
if (!outFile) {
console.error("Please provide an output file.");
return false;
}
if (!file.endsWith(".ts") && !file.endsWith(".tsx")) {
console.error("Please provide a .ts file to bundle.");
console.error("Given file: ", file);
return false;
}
if (!outFile.endsWith(".js")) {
console.error("Please provide a .js output file.");
console.error("Given file: ", outFile);
return false;
}
const [denoLoader, denoResolver] = denoPlugins({
loader: "native",
});
await esbuild.build({
plugins: [
denoLoader,
solidPlugin({
solid: {
moduleName: "npm:solid-js/web",
},
}),
denoResolver,
],
entryPoints: [file],
outfile: outFile,
bundle: true,
format: "esm",
jsx: "automatic",
tsconfigRaw: {
compilerOptions: {
experimentalDecorators: true,
},
},
// treeShaking: true,
// minify: true,
// Minify is required for dead code elimination, tree shaking doesn't
// remove: `if (false) { ... }` statements.
// minifySyntax: true,
// minifyWhitespace: true,
// minify: true,
define: {
// Deno: "false",
// Deno: JSON.stringify({
// build: {
// os: "browser", // Deno database uses browser key
// },
// }),
},
});
}
// Get first argument
const file = Deno.args[0];
const outFile = Deno.args[1];
await buildTsFile(file, outFile);