-
-
Notifications
You must be signed in to change notification settings - Fork 239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
how to keep original directory structure? #728
Comments
I want is code split,like this: dist
- tool1
- tool1.js
- tool1.mjs
- tool2
- tool2.js
- tool2.mjs
- tool3
- tool3.js
- tool3.mjs
- index.js
- index.mjs |
An approach I take to achieve something similar is to set up import glob from 'tiny-glob'
import { defineConfig } from 'tsup'
export default defineConfig(async () => {
return [
{
entry: await glob('./src/**/!(*.d|*.spec).ts'), |
Maybe to elaborate, this seems appropriate when building libraries of React component or libraries of independant utilities (lodash style), see: https://stackoverflow.com/questions/72149666/a-fool-proof-tsup-config-for-a-react-component-library We seem to need:
I still struggle to keep the directory structure. If entry is Edit: here is the final result. Components are bundled with code splitting (in case 2 components use the same internal sub component for instance), index files are not bundled, only transpiled, and uses an explicit ".js" which is necessary for ESM modules to work. |
It's entry seem support glob:
|
Just to answer this precise question: outDir: "./dist",
esbuildOptions(options, context) {
// the directory structure will be the same as the source
options.outbase = "./";
},
}, The "outbase" option of esbuild will force the bundled files to have the same directory structure as the source. I've updated my Stack Overflow answer here: https://stackoverflow.com/a/73883783/5513532 At this point I am stuck with one last thing, I need to add ".js" to the imports of "index.ts" and can't find a way to do that during bundling. So I add the ".js" manually in the "index.ts" source (sounds weird, but it works), except that now it breaks storybook. |
use |
BTW if use |
One drawback to using globs in |
Have you got a change to find a solution to I guess this behavior is caused by esbuild not following any paths in the tsconfig when the bundling options is off. |
I scoured the documentation and couldn't find the |
For anybody stumbling accross the issue I ended up combining what I usually use for tsc. Setting bundle to false as expected stops following paths on esbuild side of things. I suppose this would not be a concern of tsup. From the esbuild side I could not make it work using alias plugins and injecting tsconfig in. So just used tsconfig-replace-paths cli to swap paths on onsuccess step. It is still fast and stable enough for me so that I prefer not to mark it as being a trade off. Something like as below: https://github.com/tailoredmedia/backend-nx-skeleton/blob/master/packages/nx-nest/tsup.config.ts |
Are you guys also having the issue that it gives the error on the first line
|
tried all, none of them worked 😢 |
I was trying to build a node library to use in both CJS and ESM environments and figured it out with
to:
Hope it helps someone :) |
I was trying to build a Discord bot and changing entry from |
Interestingly, using the glob pattern
Yields
But when the
Yields
Perhaps I should create a new issue for this, though. It may even be an esbuild problem. |
Sorry for tagging @egoist, could you tell us why it happens that way? #728 (comment) |
@mamlzy making an educated guess, tsup/esbuild (I do not know which is responsible) chooses the 'deepest common ancestor' (directory) for all the discovered input entrypoints and computes their paths relative to this directory. With an When |
Such as above,
src/index.ts
isexports
all, then usetsup src/index.ts --format esm,cjs,iife
build,it will output:it not I want.
Upvote & Fund
The text was updated successfully, but these errors were encountered: