Created
October 7, 2024 13:44
-
-
Save tommie/1e505f3f7a281698bdb9fdc7a303e6c0 to your computer and use it in GitHub Desktop.
Pinia Nuxt module fix for layers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { createResolver, defineNuxtModule, installModule } from '@nuxt/kit'; | |
import type { ModuleOptions } from '@pinia/nuxt'; | |
// Works around layers in Pinia. | |
// | |
// See https://github.com/vuejs/pinia/pull/2757. | |
export default defineNuxtModule<ModuleOptions>({ | |
meta: { | |
name: 'pinialayers', | |
configKey: 'pinia', | |
}, | |
defaults: { | |
disableVuex: true, | |
}, | |
async setup(options, nuxt) { | |
const resolver = createResolver(import.meta.url); | |
options.storesDirs ??= []; | |
for (const layer of nuxt.options._layers) { | |
if (layer.config.pinia?.storesDirs) { | |
options.storesDirs.push(...layer.config.pinia.storesDirs.map((storeDir) => resolver.resolve(layer.config.srcDir, storeDir))); | |
} else { | |
options.storesDirs.push(resolver.resolve(layer.config.srcDir, 'stores')); | |
} | |
} | |
await installModule('@pinia/nuxt', options, nuxt); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment