-
-
Notifications
You must be signed in to change notification settings - Fork 10.6k
feat(@react-router/dev): add defineConfig
utility
#12541
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
base: dev
Are you sure you want to change the base?
Conversation
|
defineConfig
utility
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We went back and forth on whether to add this, but we ultimately decided against it because it adds needless indirection, even though the syntax does look nicer to my eyes.
A defineConfig
function arguably makes it look like there's some kind of runtime behaviour supported here, or that it may be introduced in the future, but if it's only used to perform type checking, it felt simpler and more transparent to simply annotate the type.
Curious to hear your thoughts on this though.
@rossipedia pinging you so you can leave thoughts as well, but here are mine: I think this is more of a "standards" thing in my eyes, as the react-router plugin relies on Vite, and wraps it with with a custom command I'd expect for it to have similar config definition to Vite, something like Vitest does, I understand they integrate tightly and are built by the same people, but I feel like this function definition has become something you expect to see in the Vite ecosystem. Another thing I'd like to mention is that there are certain config flags, even though they don't provide import { defineConfig } from "@react-router/dev/config";
export default defineConfig({
vite: {
// ... vite stuff here ...
},
future: {
// RSC WHEN?!?!?
}
}) I personally feel like it's just a convinience 1 liner utility that feels warm and familiar compared to 1 million custom configs like eslint, biome, insert random json config file here. It takes 0 maintainence as it just inherits the type you have to define and manage anyway and it feels more in line with Vite. |
So yeah, I agree with @AlemTuzlak on the "standards" thing, although I'd probably phrase it more like a "comfortable convention". Even though it's a one liner, the goal is to improve the DX of configuring things, rather than imply that it's doing more than just type-coercion. Since RR framework relies on The benefits are tangible, IMO though, rather than philosophical. Imagine a dev finds themselves where they need to create a Autocomplete in VSCode shows more than just ![]() Using They see Some samples of packages that expose this pattern (definitely not exhaustive): // vite
import { defineConfig } from 'vite';
export default defineConfig({
...
});
// vitest
import { defineConfig } from 'vitest/config';
export default defineConfig({
...
});
// playwright
import { defineConfig } from '@playwright/test';
export default defineConfig({
...
});
// solid start
import { defineConfig } from "@solidjs/start/config";
export default defineConfig({
...
});
// cypress
import { defineConfig } from 'cypress'
export default defineConfig({
...
})
// sanity
import {defineConfig} from 'sanity'
export default defineConfig({
...
})
// etc... IMO, from what I can see this is a fairly established pattern to provide easier type-assistance for configuration. Personally, I find import type { Config } from 'lib';
// feels brittle for some reason
export default {
} as Config; // or possibly `satisfies Config`
// also kinda yucky, having two syntactical constructs
let config: Config = {
...
};
export default config; |
Create a
vite
styledefineConfig
so you can do something like: