|
7 | 7 | addServerHandler,
|
8 | 8 | createResolver,
|
9 | 9 | defineNuxtModule,
|
| 10 | + resolvePath, |
10 | 11 | } from '@nuxt/kit'
|
11 | 12 | import type { NuxtModule } from '@nuxt/schema'
|
12 | 13 | // cannot import from firebase-admin because the build fails, maybe a nuxt bug?
|
@@ -191,6 +192,45 @@ const VueFire: NuxtModule<VueFireNuxtModuleOptions> =
|
191 | 192 | { from: 'vuefire', name: 'useDatabaseObject' },
|
192 | 193 | ])
|
193 | 194 | },
|
| 195 | + |
| 196 | + // NOTE: workaround until https://github.com/vitejs/vite/issues/11114 is fixed |
| 197 | + hooks: { |
| 198 | + // Resolve the correct firebase/firestore path on server only since vite is resolving the wrong one in dev |
| 199 | + 'vite:extendConfig': async (config, { isServer }) => { |
| 200 | + if (isServer) { |
| 201 | + config.resolve ??= {} |
| 202 | + config.resolve.alias ??= {} |
| 203 | + |
| 204 | + // skip the whole thing if the alias is already set in user config |
| 205 | + // @ts-ignore |
| 206 | + if (!config.resolve.alias['firebase/firestore']) { |
| 207 | + // this gives an absolute path which is needed for the alias to work since the firebase package is not including the dist folder in exports |
| 208 | + const resolvedFirestore = await resolvePath('firebase/firestore') |
| 209 | + const resolvedFirestoreMJS = |
| 210 | + resolvedFirestore.slice( |
| 211 | + 0, |
| 212 | + resolvedFirestore.lastIndexOf('dist') |
| 213 | + ) + 'dist/index.mjs' |
| 214 | + // @ts-ignore |
| 215 | + config.resolve.alias['firebase/firestore'] = resolvedFirestoreMJS |
| 216 | + |
| 217 | + const resolvedNamespacedFirestore = await resolvePath( |
| 218 | + '@firebase/firestore' |
| 219 | + ) |
| 220 | + const resolvedNamespacedFirestoreMJS = |
| 221 | + resolvedNamespacedFirestore.slice( |
| 222 | + 0, |
| 223 | + resolvedNamespacedFirestore.lastIndexOf('dist') |
| 224 | + ) + 'dist/index.node.mjs' |
| 225 | + // @ts-ignore |
| 226 | + config.resolve.alias['@firebase/firestore'] = |
| 227 | + resolvedNamespacedFirestoreMJS |
| 228 | + } |
| 229 | + |
| 230 | + // add any other firebase alias you need |
| 231 | + } |
| 232 | + }, |
| 233 | + }, |
194 | 234 | })
|
195 | 235 |
|
196 | 236 | // just to have autocomplete and errors
|
|
0 commit comments