Skip to content

Commit be99b39

Browse files
committed
chore: update tsup config
having some issues with solid-tsup-preset sporadically building .mjs instead of .js files. based new config on https://github.com/solidjs-community/solid-lib-starter/blob/f1d2d2b2db286b967916d25a729940c46026b7a1/tsup.config.ts see solidjs-community/tsup-preset-solid#16
1 parent eacf21d commit be99b39

File tree

2 files changed

+66
-45
lines changed

2 files changed

+66
-45
lines changed

package.json

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,31 +32,35 @@
3232
},
3333
"exports": {
3434
".": {
35+
"solid": {
36+
"development": "./dist/index.dev.solid.jsx",
37+
"import": "./dist/index.solid.jsx"
38+
},
3539
"development": {
3640
"import": {
37-
"types": "./dist/index/index.d.ts",
38-
"default": "./dist/index/dev.js"
41+
"types": "./dist/index.d.ts",
42+
"default": "./dist/index.dev.js"
3943
}
4044
},
4145
"import": {
42-
"types": "./dist/index/index.d.ts",
43-
"default": "./dist/index/index.js"
46+
"types": "./dist/index.d.ts",
47+
"default": "./dist/index.js"
4448
}
4549
},
4650
"./testing": {
4751
"solid": {
48-
"development": "./dist/testing/dev.jsx",
49-
"import": "./dist/testing/index.jsx"
52+
"development": "./dist/testing.dev.solid.jsx",
53+
"import": "./dist/testing.solid.jsx"
5054
},
5155
"development": {
5256
"import": {
53-
"types": "./dist/testing/index.d.ts",
54-
"default": "./dist/testing/dev.js"
57+
"types": "./dist/testing.d.ts",
58+
"default": "./dist/testing.dev.js"
5559
}
5660
},
5761
"import": {
5862
"types": "./dist/testing/index.d.ts",
59-
"default": "./dist/testing/index.js"
63+
"default": "./dist/testing.js"
6064
}
6165
}
6266
},

tsup.config.ts

Lines changed: 53 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,58 @@
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 }
256

267
export default defineConfig(config => {
278
const watching = !!config.watch
289

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+
})
4158
})

0 commit comments

Comments
 (0)