egoist / tsup

The simplest and fastest way to bundle your TypeScript libraries.
https://tsup.egoist.dev
MIT License
8.46k stars 209 forks source link

Support asset relocation like `@vercel/ncc` ? #1100

Open abcfy2 opened 3 months ago

abcfy2 commented 3 months ago

Could you please support asset relocation feature like @vercel/ncc? https://github.com/vercel/webpack-asset-relocator-loader#how-it-works

@vercel/ncc could support path.join() asset been copied to dist directory. Would you please also support this feature ?

Thanks.

Upvote & Fund

Fund with Polar

pqt commented 3 months ago

If I'm understanding you correctly, aren't you asking for this? https://tsup.egoist.dev/#copy-files-to-output-directory

abcfy2 commented 3 months ago

If I'm understanding you correctly, aren't you asking for this? https://tsup.egoist.dev/#copy-files-to-output-directory

Not just for this. @vercel/ncc could fix the path.join after assets copy.

For example. Here's the project structure:

.
`-- src
  `-- index.ts
`-- public
  `-- myimg.png

In the index.ts:

const pngFile = path.join(__dirname, '../public/myimg.png');
// ... SNIP ...

After use @vercel/ncc build, src/index.ts could be compile to dist/index.js, and public/myimg.png could copy to dist/myimg.png, and path.join should be correct after copy assets. But Copy files to output directory does not solve the path after copy.

So @vercel/ncc call this Asset Relocation.

In @vercel/ncc, if you use process.cwd(), __filename, __dirname, path.*(), require.resolve, the related files should be also copy to dist, and auto correct the path.