question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add "presets" option to Vite config

See original GitHub issue

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 calls mergeConfig on each preset before plugins are processed.

The user config is merged after any presets.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
yyx990803commented, Mar 15, 2021

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 @vitejs/plugin-legacy is doing (it contains 3 internal sub-plugins). I’m not sure if the concept of presets is really necessary when you can just do that.

2reactions
bluwycommented, Mar 13, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configuring Vite
Configuring Vite #. When running vite from the command line, Vite will automatically try to resolve a config file named vite.config.js inside project...
Read more >
Using Plugins - Vite
Using Plugins #. Vite can be extended using plugins, which are based on Rollup's well-designed plugin interface with a few extra Vite-specific options....
Read more >
Building for Production - Vite
If you are deploying your project under a nested public path, simply specify the base config option and all asset paths will be...
Read more >
Plugin API - Vite
Users will add plugins to the project devDependencies and configure them ... plugins also accepts presets including several plugins as a single element....
Read more >
Building for Production - Vite
defaults and supports es6-module and supports es6-module-dynamic-import, ... You can specify custom targets via the build.target config option, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found