|
1 | | -import { build, BuildOptions } from "esbuild"; |
2 | | -import { solidPlugin } from "esbuild-plugin-solid"; |
| 1 | +import { dirname } from "path"; |
| 2 | +import { build, InlineConfig } from "vite"; |
| 3 | +import solidPlugin from "vite-plugin-solid"; |
3 | 4 | import { worker } from "workerpool"; |
4 | 5 |
|
| 6 | +function getOptions(filePath: string, server: boolean): InlineConfig { |
| 7 | + return { |
| 8 | + build: { |
| 9 | + lib: { |
| 10 | + entry: filePath, |
| 11 | + formats: ["es"], |
| 12 | + }, |
| 13 | + outDir: dirname(filePath), |
| 14 | + minify: true, |
| 15 | + sourcemap: true, |
| 16 | + write: true, |
| 17 | + emptyOutDir: false, |
| 18 | + rollupOptions: { |
| 19 | + input: filePath, |
| 20 | + external: ["solid-js", "solid-js/web"], |
| 21 | + output: { |
| 22 | + entryFileNames: server ? "index.ssr.js" : "index.js", |
| 23 | + }, |
| 24 | + }, |
| 25 | + ssr: server, |
| 26 | + }, |
| 27 | + plugins: [ |
| 28 | + solidPlugin({ |
| 29 | + babel: { compact: true }, |
| 30 | + solid: { hydratable: !server, generate: server ? "ssr" : "dom" }, |
| 31 | + ssr: server, |
| 32 | + dev: false, |
| 33 | + }), |
| 34 | + ], |
| 35 | + }; |
| 36 | +} |
| 37 | + |
5 | 38 | /** |
| 39 | + * Bundle the icons with vite and vite-plugin-solid |
| 40 | + * |
| 41 | + * This builds two bundles, one for the client and one for the server. |
6 | 42 | */ |
7 | 43 | export async function postBuild(filePath: string) { |
8 | | - // build the tsx file with esbuild |
9 | | - const esbuildOptions: BuildOptions = { |
10 | | - entryPoints: [filePath], |
11 | | - bundle: true, |
12 | | - minify: true, |
13 | | - sourcemap: true, |
14 | | - target: "es2021", |
15 | | - write: true, |
16 | | - }; |
| 44 | + process.env.NODE_ENV = "production"; |
17 | 45 | await Promise.all([ |
18 | | - build({ |
19 | | - ...esbuildOptions, |
20 | | - format: "esm", |
21 | | - outfile: filePath.replace(".ts", ".js"), |
22 | | - plugins: [solidPlugin({ babel: { compact: true } })], |
23 | | - }), |
24 | | - build({ |
25 | | - ...esbuildOptions, |
26 | | - format: "cjs", |
27 | | - outfile: filePath.replace(".ts", ".cjs"), |
28 | | - plugins: [ |
29 | | - solidPlugin({ |
30 | | - babel: { compact: true }, |
31 | | - solid: { generate: "ssr", hydratable: true }, |
32 | | - }), |
33 | | - ], |
34 | | - }), |
| 46 | + // Build the client bundle |
| 47 | + build(getOptions(filePath, false)), |
| 48 | + // Build the server bundle |
| 49 | + build(getOptions(filePath, true)), |
35 | 50 | ]); |
36 | 51 | } |
37 | 52 |
|
|
0 commit comments