-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
feat: supports compiling TS module files #15863
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
Conversation
|
|
Before you go too far: I don't think this is a good idea...there's already a tool to do this and it's the typescript compiler. Inside svelte files it's a different story because the typescript compiler can't operate there but for .ts files there's really no reason to add the maintenance burden in svelte. Furthermore acorn typescript can only compile deletable TS which, while arguably a better default, it's not the same. |
|
Hello @paoloricciuti, thanks for the heads up! Indeed, this looks like a dead end. I'm running more experiment before closing this draft. Like for |
This feels a job for another bun plugin rather than the svelte compiler...however, shouldn't bun understand ts natively? |
It absolutely does. However, since the runes inside Svelte error: rune_outside_svelte
The `$state` rune is only available inside `.svelte` and `.svelte.js/ts` fileswhen trying to run it. |
|
Oh gotcha...yeah that's an annoying problem 🤔 |
|
I couldn't find a viable workaround with Typescript svelte modules. The way I could test svelte modules with Bun tester:
|
|
I know nothing about Bun bundler plugins but the way it works for Vite/Rollup/Webpack is that the typescript transpiled plug-in runs first and then the Svelte plugin can be called with the transpiled JavaScript to transpiled runes. |
Indeed, or at least I couldn't find anything like this.
I'll git this a try! Thanks for all the ideas |
|
You can also do what we are doing in the repl and use |
|
What a brilliant idea @paoloricciuti! ts-blank-space did perfect job. import { file, plugin } from 'bun'
import { compileModule } from 'svelte/compiler'
import removeTS from 'ts-blank-space'
plugin({
name: 'bun-svelte-module',
async setup(build) {
build.onLoad({ filter: /\.svelte\.[j|t]s$/ }, async ({ path }) => {
const text = await file(path).text()
const isTS = path.endsWith('.ts')
return {
contents: compileModule(isTS ? removeTS(text) : text, {
filename: path,
generate: 'client'
}).js.code,
loader: 'js'
}
})
}
}) |
Work in progress.
This PR allows to parse and compile module files (
*.svelte.ts) written in TypeScript.More context to come.
Before submitting the PR, please make sure you do the following
feat:,fix:,chore:, ordocs:.packages/svelte/src, add a changeset (npx changeset).Tests and linting
pnpm testand lint the project withpnpm lint