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

Plugins cannot add other plugins in config() hook #2484

Closed
3 tasks done
marvinhagemeister opened this issue Mar 12, 2021 · 1 comment
Closed
3 tasks done

Plugins cannot add other plugins in config() hook #2484

marvinhagemeister opened this issue Mar 12, 2021 · 1 comment

Comments

@marvinhagemeister
Copy link
Contributor

Describe the bug

If a plugin adds another plugin via the config() hook, then the "inner" one will be ignored. Only the outer plugin will be added. My goal is to create a wrapper plugin for Preact applications that automatically sets up the prefresh plugin, devtools bridge and some custom SSR stuff.

Reproduction

Repro: https://github.com/marvinhagemeister/vite-nested-plugin-bug

  1. Clone the repo above
  2. Run npm install
  3. Run npm start and open the page
  4. Page should render "It works!"

System Info

  • vite version: 2.0.5
  • Operating System: MacOS Big Sur
  • Node version: 15.10.0
  • Package manager (npm/yarn/pnpm) and version: npm 7.6.1
@marvinhagemeister
Copy link
Contributor Author

Alright, after lots of experimentation and an attempt to add recursively registering plugins myself, I've come to the conclusion that this would open up a can of worms. It makes config creation a lot more complex and it's unclear in which order some hooks should be processed. Much easier if the plugin tree remains flat.

Instead I found another neat way to enable presets: mergeConfig(). With that we can just pass a config around and extend it:

function withPreset(config) {
  return mergeConfig(config, {
	plugins: [foo(), bar()]
  }
);

// vite.config.ts
export default withPreset({
  // user config
})

With this the feature request becomes redundant.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant