|
1 | | -import process from "node:process" |
2 | | -import { defineConfig } from "tsup" |
3 | | -import * as preset from "tsup-preset-solid" |
4 | | - |
5 | | -const preset_options: preset.PresetOptions = { |
6 | | - entries: [ |
7 | | - { |
8 | | - entry: "src/index.ts", |
9 | | - dev_entry: true, |
10 | | - }, |
11 | | - { |
12 | | - entry: "src/testing/index.tsx", |
13 | | - name: "testing", |
14 | | - dev_entry: true, |
15 | | - }, |
16 | | - ], |
17 | | - drop_console: false, |
18 | | -} |
19 | | - |
20 | | -const CI = |
21 | | - process.env["CI"] === "true" || |
22 | | - process.env["GITHUB_ACTIONS"] === "true" || |
23 | | - process.env["CI"] === '"1"' || |
24 | | - process.env["GITHUB_ACTIONS"] === '"1"' |
| 1 | +import { solidPlugin } from "esbuild-plugin-solid" |
| 2 | +import { defineConfig, type Options } from "tsup" |
| 3 | + |
| 4 | +type Entry = { readonly entry: string; readonly name: string } |
| 5 | +type Variation = { readonly dev: boolean; readonly solid: boolean } |
25 | 6 |
|
26 | 7 | export default defineConfig(config => { |
27 | 8 | const watching = !!config.watch |
28 | 9 |
|
29 | | - const parsed_options = preset.parsePresetOptions(preset_options, watching) |
30 | | - |
31 | | - if (!watching && !CI) { |
32 | | - const package_fields = preset.generatePackageExports(parsed_options) |
33 | | - |
34 | | - console.log(`package.json: \n\n${JSON.stringify(package_fields, null, 2)}\n\n`) |
35 | | - |
36 | | - // will update ./package.json with the correct export fields |
37 | | - preset.writePackageJson(package_fields) |
38 | | - } |
39 | | - |
40 | | - return preset.generateTsupOptions(parsed_options) |
| 10 | + const packageEntries: Entry[] = [ |
| 11 | + { entry: "src/index.ts", name: "index" }, |
| 12 | + { entry: "src/testing/index.tsx", name: "testing" }, |
| 13 | + ] |
| 14 | + |
| 15 | + return packageEntries.flatMap(({ entry, name }, i) => { |
| 16 | + const packageEntries: Variation[] = [ |
| 17 | + { dev: false, solid: false }, |
| 18 | + { dev: true, solid: false }, |
| 19 | + { dev: true, solid: true }, |
| 20 | + ] |
| 21 | + |
| 22 | + return packageEntries.flatMap(({ dev, solid }, j) => { |
| 23 | + const outFilename = `${name}${dev ? ".dev" : ""}${solid ? ".solid" : ""}` |
| 24 | + |
| 25 | + return { |
| 26 | + watch: watching, |
| 27 | + target: "esnext", |
| 28 | + format: "esm", |
| 29 | + clean: i === 0, |
| 30 | + dts: j === 0, |
| 31 | + entry: { [outFilename]: entry }, |
| 32 | + treeshake: watching ? undefined : { preset: "safest" }, |
| 33 | + replaceNodeEnv: true, |
| 34 | + esbuildOptions(options) { |
| 35 | + options.define = { |
| 36 | + ...options.define, |
| 37 | + "process.env.NODE_ENV": dev ? `"development"` : `"production"`, |
| 38 | + "process.env.PROD": dev ? "false" : "true", |
| 39 | + "process.env.DEV": dev ? "true" : "false", |
| 40 | + "import.meta.env.NODE_ENV": dev ? `"development"` : `"production"`, |
| 41 | + "import.meta.env.PROD": dev ? "false" : "true", |
| 42 | + "import.meta.env.DEV": dev ? "true" : "false", |
| 43 | + } |
| 44 | + options.jsx = "preserve" |
| 45 | + |
| 46 | + if (!dev) options.drop = ["console", "debugger"] |
| 47 | + |
| 48 | + return options |
| 49 | + }, |
| 50 | + outExtension: ({ format }) => { |
| 51 | + if (format === "esm" && solid) return { js: ".jsx" } |
| 52 | + return {} |
| 53 | + }, |
| 54 | + esbuildPlugins: !solid ? [solidPlugin() as any] : undefined, |
| 55 | + } satisfies Options |
| 56 | + }) |
| 57 | + }) |
41 | 58 | }) |
0 commit comments