Skip to content

feat: Support svelte.config.ts#13935

Merged
benmccann merged 14 commits intomainfrom
feat/load-svelte-config-ts
Jul 13, 2025
Merged

feat: Support svelte.config.ts#13935
benmccann merged 14 commits intomainfrom
feat/load-svelte-config-ts

Conversation

@dominikg
Copy link
Copy Markdown
Contributor

@dominikg dominikg commented Jun 26, 2025

closes #2576

This PR enables loading svelte.config.ts in runtimes that support importing TypeScript files.
In deno and bun this should work ootb, in nodejs >=22.6 you can use the --experimental-strip-types flag to allow it.


Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

Edits

  • Please ensure that 'Allow edits from maintainers' is checked. PRs without this option may be closed.

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Jun 26, 2025

🦋 Changeset detected

Latest commit: 794b25f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@sveltejs/package Minor
@sveltejs/kit Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@svelte-docs-bot
Copy link
Copy Markdown

@dummdidumm
Copy link
Copy Markdown
Member

The lint error is from eslint which likely trips up on multiple files just with different extensions, best to ignore that directory in the config.
The other error sounds like something from the runtime, but not sure. Maybe NodeJs because the CI runs with a version which doesn't support ts files yet?

@dominikg
Copy link
Copy Markdown
Contributor Author

ugh, conditionally passing --experimental-strip-types is weird.

changed test-others to a matrix to be able to test with 22 and 18.

In a separate PR we should look into adding node24 to the matrix tests.

@benmccann
Copy link
Copy Markdown
Member

I'm not sure it makes sense to support .mjs and .mts file extensions. SvelteKit projects can only be ESM projects in which case you'd never use those extensions

@dominikg
Copy link
Copy Markdown
Contributor Author

dominikg commented Jun 27, 2025

When it was only one exact filename svelte.config.js it made the code simpler not checking svelte.config.mjs too.

Now that this PR adds checking multiple extensions, its very easy to allow mjs and mts and those are valid even in projects where "type":"module" is in package.json. They also enable custom setups where type is commonjs (eg sveltekit app embedded in a node app package).

Co-authored-by: Tee Ming <chewteeming01@gmail.com>
@benmccann
Copy link
Copy Markdown
Member

To me it's nothing about the simplicity of the code, but whether we want to encourage bad practices. There is no reason a SvelteKit project should ever lack "type": "module" or use .mjs/.mts that I can think of

@dominikg dominikg changed the title feat: Support .ts,.mjs and .mts extension for svelte.config feat: Support svelte.config.ts Jun 28, 2025
@dominikg
Copy link
Copy Markdown
Contributor Author

removed mjs and mts, lets see if someone asks for it. I know there's a few that use vite-plugin-svelte with svelte.config.mjs but SvelteKit can have different constraints.

dominikg and others added 2 commits June 28, 2025 19:32
Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com>
dominikg and others added 3 commits July 6, 2025 09:38
@teemingc teemingc added the feature / enhancement New feature or request label Jul 8, 2025
@teemingc
Copy link
Copy Markdown
Member

teemingc commented Jul 8, 2025

Should we also adjust svelte.dev to show the TS version of the config file? We currently don't https://github.com/sveltejs/svelte.dev/blob/9956e562430c0a089ce49a9864b86eab37cffb56/packages/site-kit/src/lib/markdown/renderer.ts#L375-L376

Still trying to think of other places we need to apply these TS updates to. Don't think we can switch the config file to TS in the SvelteKit TS template yet because people might still be using older Node versions.

@dominikg
Copy link
Copy Markdown
Contributor Author

dominikg commented Jul 8, 2025

I think we should land support in language-tools first and then document it with a note that it requires node24 or 22 with a flag.

There's also an open question of where to get the config type from. Kit exports it here

export interface Config {

Non-Sveltekit users shouldn't have to use the type from that, there is SvelteConfig in vite-plugin-svelte https://github.com/sveltejs/vite-plugin-svelte/blob/cb002014a3716403686482735670f9a40a7f077c/packages/vite-plugin-svelte/types/index.d.ts#L114 so

with sveltekit

import type {Config} from '@sveltejs/kit'
export default {/*...*/} satisfies Config

without sveltekit

import type {SvelteConfig} from '@sveltejs/vite-plugin-svelte'
export default {/*...*/} satisfies SvelteConfig

?

It might be good if sveltekits config type extended vite-plugin-sveltes 🤔 right now they differ slightly.

@teemingc
Copy link
Copy Markdown
Member

teemingc commented Jul 9, 2025

It might be good if sveltekits config type extended vite-plugin-sveltes 🤔 right now they differ slightly.

Oh, totally. That sounds like a good idea.

EDIT: started a PR here #13982

@benmccann benmccann merged commit 19a9597 into main Jul 13, 2025
21 checks passed
@benmccann benmccann deleted the feat/load-svelte-config-ts branch July 13, 2025 14:25
@github-actions github-actions bot mentioned this pull request Jul 11, 2025
Copilot AI pushed a commit to Stadly/kit that referenced this pull request Mar 6, 2026
Co-authored-by: Tee Ming <chewteeming01@gmail.com>
Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature / enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add typescript version of svelte.config.js

4 participants