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

Commit c307ee8

Browse files
committed
docs: heading and formatting improvements for layers
1 parent 5fe7c1c commit c307ee8

File tree

1 file changed

+47
-42
lines changed

1 file changed

+47
-42
lines changed

docs/content/1.docs/2.guide/3.going-further/7.layers.md

+47-42
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Additionally, certain other files in the layer directory will be auto-scanned an
6161

6262
::
6363

64-
## Using Starter Templates
64+
## Starter Template
6565

6666
To get started you can initialize a layer with the [nuxt/starter/layer template](https://github.com/nuxt/starter/tree/layer). This will create a basic structure you can build upon. Execute this command within the terminal to get started:
6767

@@ -75,30 +75,30 @@ Follow up on the README instructions for the next steps.
7575
Check [nuxt-themes/starter](https://github.com/nuxt-themes/starter) for a more opinionated starter for authoring Nuxt themes. It can be initialized with:
7676

7777
```bash
78-
npx nuxi init --template gh:nuxt-themes/starter my-theme
78+
npx nuxi init --template gh:nuxt-themes/starter my-theme
7979
```
8080

8181
::
8282

83-
## Publishing layers
83+
## Publishing Layers
8484

8585
You can publish and share layers by either using a remote source or an npm package.
8686

87-
### Publishing via Git Repository
87+
### Git Repository
8888

8989
You can use a git repository to share your Nuxt layer. Some examples:
9090

91-
```ts{}[nuxt.config.ts]
92-
export default defineNuxtConfig({
93-
extends: [
94-
'github:username/repoName', // GitHub Remote Source
95-
'github:username/repoName/base', // GitHub Remote Source within /base directory
96-
'github:username/repoName#dev', // GitHub Remote Source from dev branch
97-
'github:username/repoName#v1.0.0', // GitHub Remote Source from v1.0.0 tag
98-
'gitlab:username/repoName', // GitLab Remote Source example
99-
'bitbucket:username/repoName', // Bitbucket Remote Source example
100-
]
101-
})
91+
```ts [nuxt.config.ts]
92+
export default defineNuxtConfig({
93+
extends: [
94+
'github:username/repoName', // GitHub Remote Source
95+
'github:username/repoName/base', // GitHub Remote Source within /base directory
96+
'github:username/repoName#dev', // GitHub Remote Source from dev branch
97+
'github:username/repoName#v1.0.0', // GitHub Remote Source from v1.0.0 tag
98+
'gitlab:username/repoName', // GitLab Remote Source example
99+
'bitbucket:username/repoName', // Bitbucket Remote Source example
100+
]
101+
})
102102
```
103103

104104
::alert{type="info"}
@@ -109,36 +109,36 @@ If you want to extend a private remote source, you need to add the environment v
109109
Currently, with git remote sources, if a layer has npm dependencies, you will need to manually install them in the target project. We are working on this to auto-install layer dependencies with git sources.
110110
::
111111

112-
### Publishing via npm package
112+
### npm Package
113113

114114
You can publish Nuxt layers as an npm package that contains the files and dependencies you want to extend. This allows you to share your config with others, use it in multiple projects or use it privately.
115115

116116
To extend from an npm package, you need to make sure that the module is published to npm and installed in the user's project as a devDependency. Then you can use the module name to extend the current nuxt config:
117117

118-
```ts{}[nuxt.config.ts]
119-
export default defineNuxtConfig({
120-
extends: [
121-
// Node Module with scope
122-
'@scope/moduleName',
123-
// or just the module name
124-
'moduleName'
125-
]
126-
})
118+
```ts [nuxt.config.ts]
119+
export default defineNuxtConfig({
120+
extends: [
121+
// Node Module with scope
122+
'@scope/moduleName',
123+
// or just the module name
124+
'moduleName'
125+
]
126+
})
127127
```
128128

129129
To publish a layer directory as an npm package, you want to make sure that the `package.json` has the correct properties filled out. This will make sure that the files are included when the package is published.
130130

131-
```json{}[package.json]
132-
{
133-
"name": "my-theme",
134-
"version": "1.0.0",
135-
"type": "module",
136-
"main": "./nuxt.config.ts",
137-
"dependencies": {},
138-
"devDependencies": {
139-
"nuxt": "^3.0.0"
140-
}
131+
```json [package.json]
132+
{
133+
"name": "my-theme",
134+
"version": "1.0.0",
135+
"type": "module",
136+
"main": "./nuxt.config.ts",
137+
"dependencies": {},
138+
"devDependencies": {
139+
"nuxt": "^3.0.0"
141140
}
141+
}
142142
```
143143

144144
::alert{type="info"}
@@ -151,27 +151,33 @@ Now you can proceed to publish the module to npm, either publicly or privately.
151151
When publishing the layer as a private npm package, you need to make sure you log in, to authenticate with npm to download the node module.
152152
::
153153

154-
## Tips for Authoring Layers
154+
## Tips
155155

156156
### Relative Paths and Aliases
157157

158158
When importing using aliases (such as `~/` and `@/`) in a layer components and composables, note that aliases are resolved relative to the user's project paths. As a workaround, you can **use relative paths** to import them. We are working on a better solution for named layer aliases.
159159

160160
Also when using relative paths in `nuxt.config` file of a layer, (with exception of nested `extends`) they are resolved relative to user's project instead of the layer. As a workaround, use full resolved paths in `nuxt.config`:
161161

162-
```js
163-
import { fileURLToPath } from 'node:url'
162+
```js [nuxt.config.ts]
163+
import { createResolver } from '@nuxt/kit'
164+
165+
const { resolve } = createResolver(import.meta.url)
164166

165167
export default defineNuxtConfig({
166-
css: [fileURLToPath(new URL('./assets/main.css', import.meta.url))]
168+
css: [
169+
resolve('./assets/main.css')
170+
]
167171
})
168172
```
169173
170174
## Multi-Layer Support for Nuxt Modules
171175
172-
You can use the internal array `nuxt.options._layers` to support custom multi-layer handling for your modules. Example:
176+
You can use the internal array `nuxt.options._layers` to support custom multi-layer handling for your modules.
173177
174-
```js
178+
Example:
179+
180+
```js [modules/my-module.ts]
175181
export default defineNuxtModule({
176182
setup(_options, nuxt) {
177183
for (const layer of nuxt.options._layers) {
@@ -183,7 +189,6 @@ export default defineNuxtModule({
183189
```
184190
185191
**Notes:**
186-
187192
- Earlier items in the `_layers` array have higher priority and override later ones
188193
- The user's project is the first item in the `_layers` array
189194

0 commit comments

Comments
 (0)