Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

Commit

Permalink
docs: Add recommendation for controlling plugin registration order. (#…
Browse files Browse the repository at this point in the history
…8096)

Co-authored-by: Sébastien Chopin <seb@nuxtjs.com>
  • Loading branch information
miketromba and Atinux committed Oct 11, 2022
1 parent ed1c704 commit 2aa0973
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion docs/content/2.guide/2.directory-structure/1.plugins.md
Expand Up @@ -40,6 +40,22 @@ export default defineNuxtPlugin(nuxtApp => {
})
```

## Plugin Registration Order

You can control the order in which plugins are registered by prefixing a number to the file names.

For example:

```bash
plugins/
| - 1.myPlugin.ts
| - 2.myOtherPlugin.ts
```

In this example, `2.myOtherPlugin.ts` will be able to access anything that was injected by `1.myPlugin.ts`.

This is useful in situations where you have a plugin that depends on another plugin.

## Using Composables Within Plugins

You can use [composables](/guide/directory-structure/composables) within Nuxt plugins:
Expand All @@ -54,7 +70,7 @@ However, keep in mind there are some limitations and differences:

**If a composable depends on another plugin registered later, it might not work.**

**Reason:** Plugins are called in order sequencially and before everything else. You might use a composable that dependants on another plugin which is not called yet.
**Reason:** Plugins are called in order sequentially and before everything else. You might use a composable that depends on another plugin which has not been called yet.

**If a composable depends on the Vue.js lifecycle, it won't work.**

Expand Down

0 comments on commit 2aa0973

Please sign in to comment.