Skip to content

Commit

Permalink
fix: dedupe pinia
Browse files Browse the repository at this point in the history
Fix #2820
  • Loading branch information
posva committed Nov 3, 2024
1 parent 40828b6 commit 49a7039
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions packages/nuxt/src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
isNuxtMajorVersion,
addImports,
createResolver,
resolveModule,
addImportsDir,
} from '@nuxt/kit'
import type { NuxtModule } from '@nuxt/schema'
Expand Down Expand Up @@ -63,15 +62,14 @@ const module: NuxtModule<ModuleOptions> = defineNuxtModule<ModuleOptions>({
// Transpile runtime
nuxt.options.build.transpile.push(resolve(runtimeDir))

// This alias broke in Nuxt 3 so only add it in Nuxt 2
if (isNuxtMajorVersion(2, nuxt)) {
// Make sure we use the mjs build for pinia
nuxt.options.alias.pinia =
nuxt.options.alias.pinia ||
// FIXME: remove this deprecated call. Ensure it works in Nuxt 2 to 3
resolveModule('pinia/dist/pinia.mjs', {
paths: [nuxt.options.rootDir, import.meta.url],
})
// dedupe pinia only if not building for SSR
// https://github.com/vitejs/vite-plugin-vue/blob/main/packages/plugin-vue/src/index.ts#L221
if (!nuxt.options.vite?.build?.ssr) {
nuxt.options.vite.resolve ??= {}
nuxt.options.vite.resolve.dedupe ??= []
if (!nuxt.options.vite.resolve.dedupe.includes('pinia')) {
nuxt.options.vite.resolve.dedupe.push('pinia')
}
}

nuxt.hook('prepare:types', ({ references }) => {
Expand Down

0 comments on commit 49a7039

Please sign in to comment.