-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
Add "presets" option to Vite config #2500
Comments
Some extra context. If the preset needs to be configured, frameworks and libs tools like tailwind or windicss can provide a factory to build the preset, following the same pattern as plugins. Example with export default {
presets: [ preact({ ... }), windiCSS({ ... }) ],
// user options
}) Preact now provides export default withPreact( withWindiCSS({
// user options
}) SvelteKit is also talking about providing a Preset @antfu was proposing extending export default defineConfig(
preact({ ... }),
windiCSS({ ... }),
{
// user options
}
}) (he used the name I think that both adding a |
FWIW, a preset can also be written as a plugin. It can add other plugins by having the preset function to return an array of plugins instead, e.g. https://gist.github.com/bluwy/18b8d103cea5f823a95c4ce39d36a048. Vite will flatten the plugins before resolving them. Though it doesn't look as simple as just exporting a config object/function. |
@bluwy TIL, didn't know that it was possible to return arrays there! |
on this basis, hope to support async export of vite/packages/vite/src/node/config.ts Line 705 in 5ec13d8
|
What @bluwy pointed out: Vite actually accepts nested array of plugins so you can do: const myPlugin = () => [subPluginA(), subPluginB()]
export default {
plugins: [myPlugin()]
} This is essentially what |
Releasing this preset to the public sparked a discussions on how presets should be done in vite. Presumably we were the first project to do so. It turns out that plugins can be an array of plugins. This makes the config more composable and we can avoid using a somewhat internal function to merge configs. See this issue for more background: vitejs/vite#2500
Releasing this preset to the public sparked a discussions on how presets should be done in vite. Presumably we were the first project to do so. It turns out that plugins can be an array of plugins. This makes the config more composable and we can avoid using a somewhat internal function to merge configs. See this issue for more background: vitejs/vite#2500
Is your feature request related to a problem? Please describe.
Currently, plugins cannot add other plugins. #2484
Describe the solution you'd like
Add
presets
array option, which callsmergeConfig
on each preset before plugins are processed.The user config is merged after any presets.
The text was updated successfully, but these errors were encountered: