You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 6, 2023. It is now read-only.
Copy file name to clipboardexpand all lines: docs/content/1.docs/2.guide/3.going-further/7.layers.md
+47-42
Original file line number
Diff line number
Diff line change
@@ -61,7 +61,7 @@ Additionally, certain other files in the layer directory will be auto-scanned an
61
61
62
62
::
63
63
64
-
## Using Starter Templates
64
+
## Starter Template
65
65
66
66
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:
67
67
@@ -75,30 +75,30 @@ Follow up on the README instructions for the next steps.
75
75
Check [nuxt-themes/starter](https://github.com/nuxt-themes/starter) for a more opinionated starter for authoring Nuxt themes. It can be initialized with:
'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
+
})
102
102
```
103
103
104
104
::alert{type="info"}
@@ -109,36 +109,36 @@ If you want to extend a private remote source, you need to add the environment v
109
109
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.
110
110
::
111
111
112
-
### Publishing via npm package
112
+
### npm Package
113
113
114
114
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.
115
115
116
116
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:
117
117
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
+
exportdefaultdefineNuxtConfig({
120
+
extends: [
121
+
// Node Module with scope
122
+
'@scope/moduleName',
123
+
// or just the module name
124
+
'moduleName'
125
+
]
126
+
})
127
127
```
128
128
129
129
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.
130
130
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"
141
140
}
141
+
}
142
142
```
143
143
144
144
::alert{type="info"}
@@ -151,27 +151,33 @@ Now you can proceed to publish the module to npm, either publicly or privately.
151
151
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.
152
152
::
153
153
154
-
## Tips for Authoring Layers
154
+
## Tips
155
155
156
156
### Relative Paths and Aliases
157
157
158
158
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.
159
159
160
160
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`:
0 commit comments