-
-
Notifications
You must be signed in to change notification settings - Fork 42
Support for custom loaders is missing in tsdown (and not documented in migration guide) #162
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
Comments
To add a bit more context, tsup leverage esbuild's loader feature and exposes it as a custom Rolldown exposes a similar -experimental- option called module types. Then having "custom loader" should already be possible by overriding Rolldown's config like so : // tsdown.config.ts
import { defineConfig } from 'tsdown'
export default defineConfig({
entry: ['./src/index.ts'],
// Override Rolldown's input options here
inputOptions: {
moduleTypes: {
'.custom': 'json',
},
}
}) However, in your case @mhdcodes , an |
Alright so the Rolldown engine (in Rust) actually has the But the TypeScript package's ModuleTypes enum does not exposes it for some reason. Using the // tsdown.config.ts
import { defineConfig } from 'tsdown'
export default defineConfig({
entry: ['./src/index.ts'],
inputOptions: {
moduleTypes: {
// @ts-expect-error
'.astro': 'asset',
},
}
}) But it seems like an issue in Rolldown's TypeScript package to me. |
I will try this an let you know @Gugustinette thanks for the valuable feedback. |
apparently this doesn't work: For the "moduleTypes..astro". Invalid type: Expected ("base64" | "binary" | "css" | "dataurl" | "empty" | "js" | "json" | "jsx" | "text" | "ts" | "tsx") but received "asset". |
Oh yeah it seems they have a ModuleTypes validator so it's not just some type error. I'll open the issue on Rolldown's repo. |
can we use some rollup plugins for assets like |
<!-- Thank you for contributing! --> ### Description <!-- Please insert your description here and provide especially info about the "what" this PR is solving --> Fixes #4363 The Rust `ModuleType` enum and it's `impl`s were slightly misaligned, so fixed those as well. ### Context I'm trying to migrate to `tsdown`, but need the custom loader support rolldown/tsdown#162
It seems the issue was resolved on Rolldown's side, now we are waiting for a release. |
Should import { defineConfig } from 'tsup'
export default defineConfig({
entry: ['src/index.ts'],
format: ['esm'],
loader: {
'.jpg': 'copy',
},
}) yields an almost identical config (which has an error for unknown import { defineConfig } from 'tsdown'
export default defineConfig({
entry: ['src/index.ts'],
format: ['esm'],
loader: {
'.jpg': 'copy',
},
}) I would expect the import { defineConfig } from 'tsdown'
export default defineConfig({
entry: ['src/index.ts'],
format: ['esm'],
inputOptions: {
moduleTypes: {
'.jpg': 'asset',
},
},
}) |
Latest canary includes the fix. |
Added via 7132a58 |
The current version of tsdown does not support [custom loaders], whereas tsup does https://tsup.egoist.dev/#custom-loader.
This isn’t mentioned anywhere in the migration guide, so users relying on this functionality will hit a wall trying to migrate, in fact we rely on this for an open source astro project codiume/orbit#998, I only discovered this when I tried to migrate from tsup to tsdown. we use custom loaders to skip parsing
.astro
filesQuestions / Roadmap:
Are there plans to add loader support in a future tsdown release?
If not, could the migration guide be updated to explicitly note this limitation and suggest any recommended patterns or plugins?
The text was updated successfully, but these errors were encountered: