From 90beed4921292ad79b776f343108cfa27df902ac Mon Sep 17 00:00:00 2001 From: miketromba Date: Mon, 10 Oct 2022 15:11:28 -0400 Subject: [PATCH 1/3] docs: Add recommendation for controlling plugin registration order. Controlling the order of plugin registration is a common requirement, so I think this should be added as an explicit recommendation in the docs. Right now, it just says "Plugins are called in order sequentially and before everything else" in a small part of the docs. I don't think it's verbose enough. A section titled something like "Plugin registration order" would be very helpful. From discussion https://github.com/nuxt/framework/discussions/1260#discussioncomment-3842023 --- .../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..633d417c3eb 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.** From c126e64d44038c8c1f58b675a825c72cf265373f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Chopin?= Date: Tue, 11 Oct 2022 14:13:46 +0200 Subject: [PATCH 2/3] Update docs/content/2.guide/2.directory-structure/1.plugins.md --- docs/content/2.guide/2.directory-structure/1.plugins.md | 2 +- 1 file changed, 1 insertion(+), 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 633d417c3eb..71a4a47a5ed 100644 --- a/docs/content/2.guide/2.directory-structure/1.plugins.md +++ b/docs/content/2.guide/2.directory-structure/1.plugins.md @@ -47,7 +47,7 @@ You can control the order in which plugins are registered by prefixing a number For example: ```bash -plugins +plugins/ | - 1.myPlugin.ts | - 2.myOtherPlugin.ts ``` From 860f0ee714452196a339c9e6576f446ee81625c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Chopin?= Date: Tue, 11 Oct 2022 14:13:51 +0200 Subject: [PATCH 3/3] Update docs/content/2.guide/2.directory-structure/1.plugins.md --- docs/content/2.guide/2.directory-structure/1.plugins.md | 2 +- 1 file changed, 1 insertion(+), 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 71a4a47a5ed..15e0d61782d 100644 --- a/docs/content/2.guide/2.directory-structure/1.plugins.md +++ b/docs/content/2.guide/2.directory-structure/1.plugins.md @@ -52,7 +52,7 @@ plugins/ | - 2.myOtherPlugin.ts ``` -In this example, "2.myOtherPlugin.ts" will be able to access anything that was injected by "1.myPlugin.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.