docs: add example of 'alphabetical' plugin numbering (#20930)

This commit is contained in:
Aziz Ramdan Kurniawan 2023-05-18 20:09:31 +07:00 committed by GitHub
parent 891ba880e2
commit 4d0c9bf679
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -67,20 +67,24 @@ If you are using an object-syntax plugin, the properties may be statically analy
## Plugin Registration Order ## Plugin Registration Order
You can control the order in which plugins are registered by prefixing a number to the file names. You can control the order in which plugins are registered by prefixing with 'alphabetical' numbering to the file names.
For example: For example:
```bash ```bash
plugins/ plugins/
| - 1.myPlugin.ts | - 01.myPlugin.ts
| - 2.myOtherPlugin.ts | - 02.myOtherPlugin.ts
``` ```
In this example, `2.myOtherPlugin.ts` will be able to access anything that was injected by `1.myPlugin.ts`. In this example, `02.myOtherPlugin.ts` will be able to access anything that was injected by `01.myPlugin.ts`.
This is useful in situations where you have a plugin that depends on another plugin. This is useful in situations where you have a plugin that depends on another plugin.
::alert{type=info icon=💡}
In case you're new to 'alphabetical' numbering, remember that filenames are sorted as strings, not as numeric values. For example, `10.myPlugin.ts` would come before `2.myOtherPlugin.ts`. This is why the example prefixes single digit numbers with `0`.
::
## Using Composables Within Plugins ## Using Composables Within Plugins
You can use [composables](/docs/guide/directory-structure/composables) within Nuxt plugins: You can use [composables](/docs/guide/directory-structure/composables) within Nuxt plugins: