Skip to content

Support Typescript decorator metadata #87

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

Open
nitedani opened this issue Mar 26, 2025 · 1 comment
Open

Support Typescript decorator metadata #87

nitedani opened this issue Mar 26, 2025 · 1 comment

Comments

@nitedani
Copy link
Member

nitedani commented Mar 26, 2025

Vite uses esbuild to transpile TypeScript into JavaScript
Esbuild doesn't support emitting typescript decorator metadata. evanw/esbuild#257

Solution: avoid Vite's esbuild transpilation and use swc instead. (until Rolldown is here and supports this)

There are multiple ways to do add the swc transform:

Setting esbuild: false in Vite config,
Adding the swc transform using the Vite transform hook:
Example implementation: https://github.com/unplugin/unplugin-swc/blob/main/src/index.ts

Adding an esbuild plugin to esbuild.plugins that does the swc transform:
Example implementation: https://github.com/Fullscript/esbuild-plugin-swc/blob/main/src/index.ts

So the implementation would be pretty simple.
We can add a config to enable this behavior, so this wouldn't be the default, but it could be enabled.
Something like: server.swc: boolean | Options, default: false

Alternatively we can mention this shortcoming in the docs and guide users to add support themselves. (to avoid including unnecessary dependencies in vike-server, swc downloads around 30MB of binaries)

But it would be nice to have support built-in. 😄

@nitedani nitedani changed the title Support Typescript decorators Support Typescript decorator metadata Mar 26, 2025
@magne4000
Copy link
Member

🤔 I'm not sure how common the usage of decorator is right now, so until we have multiple user reporting issues, I would only mention somewhere in the doc that one can use esbuild-plugin-swc in their Vite config.

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

No branches or pull requests

2 participants