-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Auto Register stores dir in all layers #2757
base: v2
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { fileURLToPath } from 'node:url' | ||
import { defineNuxtConfig } from 'nuxt/config' | ||
import { dirname, join } from 'path' | ||
|
||
const currentDir = dirname(fileURLToPath(import.meta.url)) | ||
|
||
export default defineNuxtConfig({ | ||
pinia: { | ||
storesDirs: [join(currentDir, './stores/**')], | ||
}, | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { ref } from 'vue' | ||
|
||
export const useLayerStore = defineStore('layerStore', () => { | ||
console.log('I was defined within a stores directory in example-layer') | ||
const state = ref('store state') | ||
return { | ||
state, | ||
} | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,9 +91,12 @@ const module: NuxtModule<ModuleOptions> = defineNuxtModule<ModuleOptions>({ | |
{ from: composables, name: 'storeToRefs' }, | ||
]) | ||
|
||
if (!options.storesDirs) { | ||
// resolve it against the src dir which is the root by default | ||
options.storesDirs = [resolver.resolve(nuxt.options.srcDir, 'stores')] | ||
if (options.storesDirs == null) { | ||
// Add stores directory for each layer, including the main src dir | ||
options.storesDirs = [] | ||
for (const layer of nuxt.options._layers) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's use a public API for layers. I don't know what it is but surely there must be a way to resolve the layers from the options, maybe with a nuxt hook? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
options.storesDirs.push(resolver.resolve(layer.config.srcDir, 'stores')) | ||
} | ||
} | ||
|
||
if (options.storesDirs) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we don't need to change the playground code. We can treat the current playground as a layer. Refer to #2828.
What do you think ?@posva
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not. I will need to take a proper look next time