Nuxt Layer support #2378
Replies: 6 comments 4 replies
-
I really cant figure out what you mean. At first glance this looks like a project specific problem or at the very least like it could be hosted in another package so I’m moving this to a discussion for anybody who want to collaborate on it |
Beta Was this translation helpful? Give feedback.
-
I also faced the situation when it is required to use some Pinia store(s) in the Nuxt layer app for some base things, but then to reuse it in the Nuxt app that extends such layer. |
Beta Was this translation helpful? Give feedback.
-
@marcelxpfeifer Does Pinia store copying from the layer into another app work for you? I tried as well, but it drops an error: And, yes, I added So, I'm still trying to find a solution. |
Beta Was this translation helpful? Give feedback.
-
@marcelxpfeifer @maxdzin I was able to get this to work by using a relative path and forcing pinia to go up a directory. Here's my directory structure (it's a monorepo): repo
site // my main nuxt3 site
my-layer // the layer that's importing the store, for use in site
nuxt.config.js // example below
stores
my-store.js
export default defineNuxtConfig({
pinia: {
storesDirs: [
'../my-layer/stores/**' // the `../` is important here
]
}
}) As seen here, since pinia imports stores relative to the project (which in my case, would be the for (const storeDir of options.storesDirs) {
addImportsDir(resolver.resolve(nuxt.options.rootDir, storeDir))
} The Nuxt docs allude to using relative paths inside layers here but it's not always exactly clear when to do so. Seems to be best to almost always use relative paths if you need to import things from a layer. |
Beta Was this translation helpful? Give feedback.
-
I've found a reasonable workaround. As you can seen here the "@pinia/nuxt" module is just adding the stores directory to the importDirs of the Nuxt config. You can do the same yourself in the nuxt.config.js of the layer project: ` export default defineNuxtConfig({ You can do the same in your Site config as well. And the stores defined in both the places will be available in the site app. resolve() is the key here. |
Beta Was this translation helpful? Give feedback.
-
Did anyone try vitest with layer pinia stores? I get a lot of |
Beta Was this translation helpful? Give feedback.
-
What problem is this solving
Allow the possibility to use pinia with nuxt layers.
Proposed solution
It would be awesome to have Nuxt layer support similar to nuxt/i18n, where the default stores are extended from the base project, but can be overwritten in the layer on top.
Describe alternatives you've considered
Currently all stores need to be copied into the extend layer as well.
Beta Was this translation helpful? Give feedback.
All reactions