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.

cannot add new plugins in options hooks on dev mode

See original GitHub issue

Describe 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

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
bluwycommented, Aug 28, 2022

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.

1reaction
PPetaucommented, Aug 25, 2022

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:

function testPlugin() {
  return [
    {
      name: "test1",
    },
    {
      name: "test2",
    },
  ];
}
Read more comments on GitHub >

github_iconTop 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 >

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