| 3 | import { solidPlugin } from "npm:esbuild-plugin-solid"; |
| 4 | |
| 5 | async function bundleSolidJSApp(file: string, outFile: string) { |
| 6 | if (!file) { |
| 7 | console.error("Please provide a file to bundle."); |
| 8 | return false; |
| 9 | } |
| 10 | |
| 11 | if (!outFile) { |
| 12 | console.error("Please provide an output file."); |
| 13 | return false; |
| 14 | } |
| 15 | |
| 16 | if (!file.endsWith(".ts") && !file.endsWith(".tsx")) { |
| 17 | console.error("Please provide a .ts file to bundle."); |
| 18 | console.error("Given file: ", file); |
| 19 | return false; |
| 20 | } |
| 21 | |
| 22 | if (!outFile.endsWith(".js")) { |
| 23 | console.error("Please provide a .js output file."); |
| 24 | console.error("Given file: ", outFile); |
| 25 | return false; |
| 26 | } |
| 27 | |
| 28 | const [denoResolver, denoLoader] = [ |
| 29 | ...denoPlugins({ |
| 30 | configPath: Deno.cwd() + "/deno.json", |
| 31 | importMapURL: import.meta.resolve("../../import_map.json"), |
| 32 | }), |
| 33 | ]; |
| 34 | await esbuild.build({ |
| 35 | entryPoints: [file], |
| 36 | outfile: outFile, |
| 37 | bundle: true, |
| 38 | format: "esm", |
| 39 | treeShaking: false, |
| 40 | minify: false, |
| 41 | plugins: [ |
| 42 | denoResolver, |
| 43 | |
| 44 | // Solid handles the JSX, so it needs to be sandwiched between the deno plugins |
| 45 | solidPlugin({ |
| 46 | solid: { |
| 47 | moduleName: "solid-native-renderer", |
| 48 | generate: "universal", |
| 49 | }, |
| 50 | }) as any, |
| 51 | |
| 52 | denoLoader, |
| 53 | ], |
| 54 | }); |
| 55 | } |
| 56 | |
| 57 | // Get first argument |
| 58 | const file = Deno.args[0]; |