( options: FreshBundleOptions, )
| 32 | const PREACT_ENV = Deno.env.get("PREACT_PATH"); |
| 33 | |
| 34 | export async function bundleJs( |
| 35 | options: FreshBundleOptions, |
| 36 | ): Promise<BuildOutput> { |
| 37 | if (esbuild === null) { |
| 38 | await startEsbuild(); |
| 39 | } |
| 40 | |
| 41 | try { |
| 42 | await Deno.mkdir(options.cwd, { recursive: true }); |
| 43 | } catch (err) { |
| 44 | if (!(err instanceof Deno.errors.AlreadyExists)) { |
| 45 | throw err; |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | const bundle = await esbuild!.build({ |
| 50 | entryPoints: options.entryPoints, |
| 51 | |
| 52 | platform: "browser", |
| 53 | target: options.target, |
| 54 | |
| 55 | format: "esm", |
| 56 | bundle: true, |
| 57 | splitting: true, |
| 58 | treeShaking: true, |
| 59 | sourcemap: options.dev ? "linked" : options.sourceMap?.kind, |
| 60 | sourceRoot: options.dev ? undefined : options.sourceMap?.sourceRoot, |
| 61 | sourcesContent: options.dev ? undefined : options.sourceMap?.sourcesContent, |
| 62 | minify: !options.dev, |
| 63 | logOverride: { |
| 64 | "suspicious-nullish-coalescing": "silent", |
| 65 | "unsupported-jsx-comment": "silent", |
| 66 | }, |
| 67 | |
| 68 | jsxDev: options.dev, |
| 69 | jsx: "automatic", |
| 70 | jsxImportSource: options.jsxImportSource ?? "preact", |
| 71 | |
| 72 | absWorkingDir: options.cwd, |
| 73 | outdir: ".", |
| 74 | write: false, |
| 75 | metafile: true, |
| 76 | |
| 77 | define: { |
| 78 | "process.env.NODE_ENV": JSON.stringify( |
| 79 | options.dev ? "development" : "production", |
| 80 | ), |
| 81 | }, |
| 82 | |
| 83 | plugins: [ |
| 84 | preactDebugger(PREACT_ENV), |
| 85 | buildIdPlugin(options.buildId), |
| 86 | windowsPathFixer(), |
| 87 | denoPlugin({ |
| 88 | preserveJsx: true, |
| 89 | debug: false, |
| 90 | publicEnvVarPrefix: "FRESH_PUBLIC_", |
| 91 | }), |
no test coverage detected