cannot add new plugins in options hooks on dev mode
See original GitHub issueDescribe the bug
I want to add another plugin inside the plugin, for example:
export default defineConfig({
plugins: [
{
name: 'test',
options(opt) {
opt.plugins ||= [];
opt.plugins.push(newPlugin);
},
},
],
});
But it only works on build mode and cannot work on dev mode.
Reproduction
https://stackblitz.com/edit/vitejs-vite-46eqxv?file=vite.config.js&terminal=dev
Expect: Hello Vue!
, actual: Hello Vite!
(pnpm run dev
)
System Info
N/A
Used Package Manager
npm
Logs
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn’t already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it’s a Vue SFC related bug, it should likely be reported to vuejs/core instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Issue Analytics
- State:
- Created a year ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
Enable this plugin only during development mode #173 - GitHub
This is already the case I believe - if you set mode to development no hooks will be attached. You can use forceEnable...
Read more >Can't add “Hook with a filter” anymore & data visible in frontend
First, the “Hook with a filter” option, we normally use to map some form-fields to some post-meta-fields stopped working on all websites. The...
Read more >Compiler Hooks | webpack
Executes a plugin during watch mode after a new compilation is triggered but before the compilation is actually started. Callback Parameters: compiler ...
Read more >The WordPress Hooks Bootcamp: How to Use Actions, Filters ...
Master Actions, Filters, and Custom Hooks by creating your own extensible plugin. Level up your WordPress dev skills now!
Read more >Managing Plugins - Jenkins
- none: if a mandatory dependant plugin exists and it is enabled, the plugin cannot be disabled (default value). - mandatory: all mandatory...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Vite also does in that a plugin can return an array of plugins. It’s definitely something we can try to explore, but my concern would be if I’d make the order confusing or has caveats.
As stated in the documentation the pluginlist is already resolved when the
config
hook is called.You could create your own plugin factory returning an array of plugins: