rolldown icon indicating copy to clipboard operation
rolldown copied to clipboard

[package/rolldown] Emit types by bundling

Open hyf0 opened this issue 1 year ago • 2 comments

          This PR solve another problem related unbundled-dts. We have met some many of them and use many workaround now.

This is not ideal. Let's try to solve it in the best suitable way. We should either use rollup-plugin-dts or https://github.com/Rich-Harris/dts-buddy to generate bundled dts files.

Originally posted by @hyf0 in https://github.com/rolldown/rolldown/issues/1387#issuecomment-2165048190

hyf0 avatar Jun 13 '24 09:06 hyf0

We are prototyping dts transform with --isolatedDeclarations in oxc, stay tuned.

But you still need another plugin if you want normal dts emit :-(

Boshen avatar Jun 13 '24 10:06 Boshen

We gonna wait for #1396 to be supported.

hyf0 avatar Jun 17 '24 03:06 hyf0

Hi, is this something that's always planned?

At Symfony UX we use Rollup with the typescript plugin to emit types when building our .ts files, but we'd like to migrate to Rolldown to reduce build time.

Is there anything we can do to help?

Thanks!

EDIT: While playing with Rolldown on https://github.com/symfony/stimulus-bridge/pull/99, I found out that it was still possible to emit types while bundling by using @rollup/plugin-typescript.

Kocal avatar Jan 25 '25 08:01 Kocal

While playing with Rolldown on https://github.com/symfony/stimulus-bridge/pull/99, I found out that it was still possible to emit types while bundling by using @rollup/plugin-typescript.

I figured that out too but noticed that the build times are significantly higher because it is using the official typescript compiler instead of the fast oxidation compiler rolldown would be using.

David-van-der-Sluijs avatar Jan 25 '25 11:01 David-van-der-Sluijs

https://github.com/sxzz/rolldown-plugin-dts is now pretty stable and will soon be integrated as a built-in plugin.

sxzz avatar Apr 16 '25 08:04 sxzz

@sxzz Does rolldown-plugin-dts depend on npm:typescript or is standalone? (to be able to generate bundled types)

pi0 avatar Apr 16 '25 08:04 pi0

@pi0 it depends on oxc-transform if isolatedDeclaration is enabled, and depend on typescript compiler if not.

sxzz avatar Apr 16 '25 08:04 sxzz

Ah ok. So for bundling, we need (rather slower) typescript dep.. Any plans to support OXC-based type bundler? (this is my main blocker right now for migration as advantage of rolldown to rollup is speed and most of build time is spent on typescript invokes)

pi0 avatar Apr 16 '25 08:04 pi0

The most challenging aspect is the lack of a native-language .d.ts emitter (except for tsgo). Undoubtedly, Oxc is currently limited to supporting isolated declarations and will remain so in the future.

The only thing we can do is wait for tsgo to become stable.

sxzz avatar Apr 16 '25 08:04 sxzz

makes sense to wait on tsgo.

~~I was hoping to achieve an isolated-type bundler for short term, bundling oxc emited isolated declarations into a single chunk. (happy to move discussion upstream if you prefer)~~ update: trying.. single bundle with isolatedDeclaration works as expected with fast speed 🚀 https://github.com/unjs/unenv/pull/497

pi0 avatar Apr 16 '25 08:04 pi0