Skip to content
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

Support svelte.config.ts #4031

Closed

Conversation

tommywalkie
Copy link

This is a continuation of #1919 and most likely #2576, making use of Vite's loadConfigFromFile to handle TypeScript config file. For now this was only tested on a local SvelteKit project.

As mentionned in most threads, the remaining issue/quirk is making it work with other Svelte tools (like the VSCode plugin, which is expecting a svelte.config.js file).

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 pnpx changeset and following the prompts. All changesets should be patch until SvelteKit 1.0

@changeset-bot
Copy link

changeset-bot bot commented Feb 21, 2022

🦋 Changeset detected

Latest commit: 90bdfda

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

This PR includes changesets to release 1 package
Name Type
@sveltejs/kit Patch

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

@dummdidumm
Copy link
Member

I don't know how I feel about this. It feels wrong to support this half-way. There's not much value if you can use this in your build but your IDE/other tooling can't deal with it. This doesn't mean I'm not open to changing this on the tooling-side of things btw.

@tommywalkie
Copy link
Author

@dummdidumm Yea pretty much. It does run the config file fine, then you inevitably find out the language server highlights your codebase in red. If anything, this could help in the future.

const resolved_config = await loadConfigFromFile(
{
command: 'build',
mode: process.env.NODE_ENV || 'production'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the || 'production' shouldn't be needed because it is done here:

process.env.NODE_ENV = process.env.NODE_ENV || 'production';

i'm worried that this might be putting it into production mode when you run svelte-kit dev

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this command needs a || 'production' (?)

kit/packages/kit/src/cli.js

Lines 147 to 153 in a8a3b14

prog
.command('package')
.describe('Create a package')
.option('-d, --dir', 'Destination directory', 'package')
.action(async () => {
try {
const config = await load_config();

Otherwise, I considered using development as the default value for NODE_ENV.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, it seems reasonable to add a production default to the package command

@benmccann
Copy link
Member

benmccann commented Feb 21, 2022

It seems somewhat reasonable to me. I'm not sure we should assume everyone uses VS Code. I'm a bit more split on whether we'd want to advertise it in the docs or not. Maybe we should caveat it there by saying the VS Code extension doesn't support it yet

@Rich-Harris
Copy link
Member

I'm a strong 👎 on this. It adds moving parts to something that should be extremely simple and foolproof, and does so using an undocumented (and thus liable to change) API that's designed to load a Vite config, not a SvelteKit config (even if it happens to work today, is it guaranteed to work in future, despite whatever changes — to either Vite or Kit — we haven't anticipated?). As noted above, it will also cause problems with other tooling.

You can already type your config files (as shown throughout the docs). The use case presented in #2576 isn't something we should encourage in the first place (I didn't actually realise that we're promoting it in the FAQ; I should pay more attention to that page). The cost to benefit ratio is all wrong.

@bluwy
Copy link
Member

bluwy commented Feb 22, 2022

-1 for me too. This wouldn't work for vite-plugin-svelte and I think it will be vital when we need to configure it in a SvelteKit project. I think we should wait for sveltejs/rfcs#59 first and slowly migrate the tooling towards it before making a new change.

@Rich-Harris
Copy link
Member

I'm going to close this as the consensus seems to be that it's not a change we should make. Perhaps we can address it at an ecosystem level eventually per the mentioned RFC. Thanks

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

Successfully merging this pull request may close these issues.

None yet

5 participants