Skip to content

Make it possible to disable code splitting #78

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

Closed
3 tasks done
tats-u opened this issue Mar 25, 2025 · 20 comments
Closed
3 tasks done

Make it possible to disable code splitting #78

tats-u opened this issue Mar 25, 2025 · 20 comments
Labels

Comments

@tats-u
Copy link

tats-u commented Mar 25, 2025

Clear and concise description of the problem

tsup can disable code splitting by the following config:

import { defineConfig } from "tsup";

export default defineConfig({
  entry: ["./src"],
  format: "esm",
  splitting: false, // !!!!!! HERE !!!!!
  dts: true,
  target: "es2021",
});

However, tsdown doesn't have such a splitting property.
Disabling code splitting improves readability and analyzability of output JS code.

tsup's doc: https://tsup.egoist.dev/#code-splitting

Suggested solution

Support splitting property

Alternative

Use tsup instead of tsdown. tsup has already been able to disable splitting.

Additional context

I tried tsdown in my packages in https://github.com/tats-u/markdown-cjk-friendly/, but gave up due to the lack of this feature.

Validations

@tats-u tats-u added the enhancement New feature or request label Mar 25, 2025
@tats-u tats-u changed the title Make it possible to disable splitting Make it possible to disable code splitting Mar 25, 2025
@sxzz
Copy link
Member

sxzz commented Mar 25, 2025

Now unsupported because of Rolldown

@tats-u
Copy link
Author

tats-u commented Mar 25, 2025

I see.

@tats-u
Copy link
Author

tats-u commented Mar 26, 2025

I found it's not supported in Rollup either.

rollup/rollup#2756

@sxzz
Copy link
Member

sxzz commented Apr 2, 2025

Is there any use cases that need disabling code splitting?

@tats-u
Copy link
Author

tats-u commented Apr 2, 2025

remarkjs/remark#1422

It looks like one of the main maintainers of remark prefer to keep .ts source and built .d.ts/.js 1:1 (one pair of .d.ts/.js per .ts).
He wants library authors to keep the published package source easily-analyzable/debuggable.

@tats-u
Copy link
Author

tats-u commented Apr 2, 2025

I personally prefer to bundle source files into single pair of .d.ts and .js.

By this, a JS runtime has only to open and parse just one JS file.

@sxzz
Copy link
Member

sxzz commented Apr 2, 2025

Maybe preserveModules is more like you needed (but Rolldown haven't implement preserveModules yet)

@tats-u
Copy link
Author

tats-u commented Apr 3, 2025

Is it a Rollup's option? I can't try it today because tsup is basically esbuild-powered. I couldn't find such an option in tsup's website.

@lishaduck
Copy link
Contributor

Is it a Rollup's option?

Yeah, it's this: https://rollupjs.org/configuration-options/#output-preservemodules

@tats-u
Copy link
Author

tats-u commented Apr 10, 2025

I googled it and it looks like what I've wanted. However I can't try it today unfortunately because I don't use Vite or Rollup to build my libraries.

@pcfreak30
Copy link

Im assuming this would prevent distX.js files (x = number) from being generated? preservemodules doesn't seem to be in tsdown.

@TheAlexLichter
Copy link
Collaborator

As @sxzz mentioned, it isn't available in Rolldown yet.

@Gugustinette Gugustinette added upstream and removed enhancement New feature or request labels Apr 30, 2025
@sxzz
Copy link
Member

sxzz commented May 7, 2025

Track rolldown/rolldown#4437

@sxzz

This comment has been minimized.

@sxzz
Copy link
Member

sxzz commented May 22, 2025

As mentioned in rolldown/rolldown#4437, unbundle mode will be landed in the next release.

@sxzz
Copy link
Member

sxzz commented May 22, 2025

The documentation has been published: https://tsdown.dev/options/unbundle

@sxzz sxzz closed this as completed May 22, 2025
@tats-u
Copy link
Author

tats-u commented May 22, 2025

I'll try it in https://github.com/tats-u/markdown-cjk-friendly later. Thank you.

@tats-u
Copy link
Author

tats-u commented May 22, 2025

The single-file bundle mode (just code splitting disabled) seems to be missing... (I don't use it for a while though)
I think tsup's splitting: false is the single-file bundle mode.

@sxzz
Copy link
Member

sxzz commented May 22, 2025

splitting: false is not fully supported at this time. As a workaround, you can specify a single entry point and enable outputOptions.inlineDynamicImports to approximate the desired behavior.

Also track rolldown/rolldown#4437 and rolldown/rolldown#3986 for future updates!

@sxzz
Copy link
Member

sxzz commented May 22, 2025

BTW, I have carefully reviewed your requirement (to generate one pair of .js and .d.ts files for each .ts file), and I can confirm that the unbundle feature already meets your needs.

Additionally, the issue title does not accurately reflect the proposed solution. To clarify: we currently recommend enabling the unbundle option to achieve the behavior of generating one pair of .js and .d.ts files for each .ts file. For information on fully disabling code splitting, please refer to rolldown/rolldown#3986 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants