Skip to content

Commit

Permalink
Merge pull request #632 from storyblok/fix/add-common-name-components…
Browse files Browse the repository at this point in the history
…-dir

fix: Add common name "componentsDir" & document it
  • Loading branch information
Dawntraoz authored Nov 6, 2023
2 parents 3cc2c16 + 360a384 commit 558c7c6
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,29 @@ To link your Vue components to the equivalent one in your Storyblok space:

- First, you need to load them globally adding them to the `~/storyblok` directory. It's important to name them with Pascal case in your code `ExampleComponent.vue` and with a hyphen inside your Storyblok space `example-component`, so they will be imported automatically.

If you want to define your own directory for the Storyblok related components, you can use the option `componentsDir` in the `nuxt.config.js`:

```js
// nuxt.config.ts
modules: [
[
"@storyblok/nuxt",
{
accessToken: "<your-access-token>",
componentsDir: false,
}
]
],
components: {
dirs: [
{
path: '~/components/storyblok',
global: true,
}
]
},
```

Otherwise, you can set another directory and load them manually (for example, by [using a Nuxt plugin](https://stackoverflow.com/questions/43040692/global-components-in-vue-nuxt)).

> **Warning**
Expand Down
7 changes: 7 additions & 0 deletions playground/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,15 @@ export default defineNuxtConfig({
region: ""
},
devtools: true,
// componentsDir: false,
// enableSudoMode: true /* (or legacy) usePlugin: false */
},
// components: {
// dirs: [{
// path: '~/components/storyblok',
// global: true,
// }]
// },
app: {
head: {
script: [{ src: "https://cdn.tailwindcss.com" }]
Expand Down
9 changes: 4 additions & 5 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface ModuleOptions {
bridge: boolean, // storyblok bridge on/off
devtools: boolean, // enable nuxt/devtools integration
apiOptions: any, // storyblok-js-client options
globalDir: string, // enable storyblok global directory for components
componentsDir: string, // enable storyblok global directory for components
}

export default defineNuxtModule<ModuleOptions>({
Expand All @@ -29,7 +29,7 @@ export default defineNuxtModule<ModuleOptions>({
usePlugin: true, // legacy opt. for enableSudoMode
bridge: true,
devtools: false,
globalDir: '~/storyblok',
componentsDir: '~/storyblok',
apiOptions: {},
},
setup(options, nuxt) {
Expand All @@ -48,9 +48,8 @@ export default defineNuxtModule<ModuleOptions>({


// Enable dirs
// nuxt.options.components.dirs = ["~/components/storyblok"];
if(options.globalDir){
addComponentsDir({ path: options.globalDir, global: true, pathPrefix: false });
if(options.componentsDir) {
addComponentsDir({ path: options.componentsDir, global: true, pathPrefix: false });
}
nuxt.options.build.transpile.push(resolver.resolve("./runtime"));
nuxt.options.build.transpile.push("@storyblok/nuxt");
Expand Down

0 comments on commit 558c7c6

Please sign in to comment.