Skip to content

Commit

Permalink
fix: avoid broken alias
Browse files Browse the repository at this point in the history
This alias breaks in some builds like nuxthub
  • Loading branch information
posva committed Oct 29, 2024
1 parent d5dbaee commit 65031ee
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions packages/nuxt/src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import {
defineNuxtModule,
addPlugin,
isNuxt2,
isNuxtMajorVersion,
addImports,
createResolver,
resolveModule,
Expand Down Expand Up @@ -54,7 +54,7 @@ const module: NuxtModule<ModuleOptions> = defineNuxtModule<ModuleOptions>({
nuxt.options.features &&
// ts
options.disableVuex &&
isNuxt2()
isNuxtMajorVersion(2, nuxt)
) {
// @ts-expect-error: no `store` feature flag in nuxt v3
nuxt.options.features.store = false
Expand All @@ -63,13 +63,16 @@ const module: NuxtModule<ModuleOptions> = defineNuxtModule<ModuleOptions>({
// Transpile runtime
nuxt.options.build.transpile.push(resolve(runtimeDir))

// 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],
})
// 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],
})
}

nuxt.hook('prepare:types', ({ references }) => {
references.push({ types: '@pinia/nuxt' })
Expand All @@ -78,7 +81,7 @@ const module: NuxtModule<ModuleOptions> = defineNuxtModule<ModuleOptions>({
// Add runtime plugin before the router plugin
// https://github.com/nuxt/framework/issues/9130
nuxt.hook('modules:done', () => {
if (isNuxt2()) {
if (isNuxtMajorVersion(2, nuxt)) {
addPlugin(resolve(runtimeDir, 'plugin.vue2'))
} else {
addPlugin(resolve(runtimeDir, 'plugin.vue3'))
Expand Down

0 comments on commit 65031ee

Please sign in to comment.