From 2aa097310cd5a490963239b8693e058d7cfef25c Mon Sep 17 00:00:00 2001 From: miketromba Date: Tue, 11 Oct 2022 08:14:18 -0400 Subject: [PATCH] docs: Add recommendation for controlling plugin registration order. (#8096) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Sébastien Chopin --- .../2.guide/2.directory-structure/1.plugins.md | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/docs/content/2.guide/2.directory-structure/1.plugins.md b/docs/content/2.guide/2.directory-structure/1.plugins.md index 27576e17c15..15e0d61782d 100644 --- a/docs/content/2.guide/2.directory-structure/1.plugins.md +++ b/docs/content/2.guide/2.directory-structure/1.plugins.md @@ -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: @@ -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.**