Hook after module installation
Hi!
I'm working on a new version of gsap nuxt module, and I want to add this new feature:
After installing the module, the terminal asks you if you want to include some plugins in your configuration.
If you answer yes, the list of available modules will be added to nuxt config.
My question is
Which hook should I use to achieve this?
Module Link:
https://github.com/LucaArgentieri/gsap-nuxt-module
GitHub
GitHub - LucaArgentieri/gsap-nuxt-module: GSAP integration for Nuxt.
GSAP integration for Nuxt. Contribute to LucaArgentieri/gsap-nuxt-module development by creating an account on GitHub.
5 Replies
Hi @Luca. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
To achieve custom logic right after your Nuxt module is installed—such as prompting the user to include plugins and updating the Nuxt config—you should use the new
- You must provide both
onInstall
hook in your module definition. This hook is specifically designed to run when the module is first installed.
Here’s how you can use it:
Important:- You must provide both
name
and version
in the meta
field for onInstall
to work.
- The onInstall
hook is only triggered on installation, not on every build or dev run.
This feature is available in Nuxt as of the referenced pull request and is intended for exactly your use case: running setup logic after module installation, such as interactive prompts and config updates. For more details, see the Nuxt PR introducing onInstall and onUpgrade hooks.
If you want to handle upgrades as well, you can also use the onUpgrade
hook in a similar way.
I'm sorry, but the knowledge sources do not provide a full example of prompting the user interactively from within the hook. However, the onInstall
hook is the correct place to implement post-install logic for your module.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@235795115954798605> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
@kapa.ai so this feature is not ready yet right?
Let me check the knowledge base for you again. One moment! :books:
----------------------
Based on the available knowledge sources, the
onInstall
and onUpgrade
hooks have been proposed and implemented in a Nuxt pull request, but there is no official documentation indicating that they are available in a stable Nuxt release yet. The feature is described in a GitHub PR and not in the main Nuxt documentation, which suggests it may not be released or documented for general use at this time feat(kit): add onInstall
and onUpgrade
module hooks.
If you need this feature, you should monitor the Nuxt release notes or the PR itself to see when it lands in a stable release. For now, it is safest to assume that this feature is not yet ready for production use unless you are using a version of Nuxt that explicitly includes it.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@235795115954798605> Kapa.ai is still learning and improving, please let me know how I did by reacting below.