-
I'm trying to build a nice tsup.config.ts/package.json combination for releasing NPM packages. I'd like: import { defineConfig } from 'tsup'
export default defineConfig({
entry: [
"src/*.ts",
"src/*/+(index|worker|*.worker).ts",
],
dts: true,
format: 'esm',
splitting: false,
sourcemap: true,
clean: true,
}) to build the {
"//": "...",
"exports": {
".": {
"import": "./dist/index.mjs",
"types": "./dist/index.d.ts"
},
"./*": {
"import": "./dist/*/index.mjs",
"types": "./dist/*/index.d.ts"
}
},
"files": [
"dist/**/*",
"package.json"
],
"//": "...",
} This should result in every top-level import { Foo } from "@scope/package/foo";
import { Bar } from "@scope/package/bar"; Package exports do not handle multiple ways to resolve a single export (I can't say, "check dist/foo.mjs, then dist/foo/index.mjs if that's missing"), so this falls on tsup or even worse, me, to setup the dist folder correctly. Does TSUP support a function like Rollup's entryFileNames? I've poked aroudn the code base and can't seem to find anything like it... |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
OK, so as tradition requires, I figured this out shortly after posting this. tsup accepts multiple configs and allows passing esbuildOptions. The solution: import { defineConfig } from 'tsup'
export default defineConfig([
{
entry: [
"src/*.ts",
],
dts: true,
format: 'esm',
splitting: false,
sourcemap: true,
clean: true,
esbuildOptions(opts, ctx) {
opts.entryNames = "[dir]/[name]/index"
}
},
{
entry: [
"src/*/+(index|worker|*.worker).ts",
],
dts: true,
format: 'esm',
splitting: false,
sourcemap: true,
clean: true,
}
]) |
Beta Was this translation helpful? Give feedback.
OK, so as tradition requires, I figured this out shortly after posting this.
tsup accepts multiple configs and allows passing esbuildOptions. The solution: