11import { fileURLToPath } from 'node:url'
2- import { resolve } from 'path'
3- import { addPlugin , defineNuxtModule } from '@nuxt/kit'
4- import { type NuxtModule } from '@nuxt/schema'
2+ import { normalize } from 'node:path'
3+ import {
4+ addPlugin ,
5+ addPluginTemplate ,
6+ createResolver ,
7+ defineNuxtModule ,
8+ } from '@nuxt/kit'
9+ import type { NuxtModule } from '@nuxt/schema'
510import { type FirebaseOptions } from '@firebase/app-types'
611
712export interface VueFireNuxtModuleOptions {
@@ -13,26 +18,28 @@ export interface VueFireNuxtModuleOptions {
1318 optionsApiPlugin ?: boolean | 'firestore' | 'database'
1419
1520 config : FirebaseOptions
21+
1622 /**
1723 * Optional name passed to `firebase.initializeApp(config, name)`
1824 */
1925 appName ?: string
2026
21- services : {
27+ services ? : {
2228 auth ?: boolean
2329 firestore ?: boolean
2430 database ?: boolean
2531 storage ?: boolean
2632 }
2733}
2834
29- const VueFireModule : NuxtModule < VueFireNuxtModuleOptions > =
35+ // Manual to avoid build error
36+ const VueFire : NuxtModule < VueFireNuxtModuleOptions > =
3037 defineNuxtModule < VueFireNuxtModuleOptions > ( {
3138 meta : {
3239 name : 'vuefire' ,
3340 configKey : 'vuefire' ,
3441 compatibility : {
35- nuxt : '^3.0.0-0 ' ,
42+ nuxt : '^3.0.0' ,
3643 } ,
3744 } ,
3845
@@ -43,12 +50,45 @@ const VueFireModule: NuxtModule<VueFireNuxtModuleOptions> =
4350 } ,
4451
4552 setup ( options , nuxt ) {
53+ const { resolve } = createResolver ( import . meta. url )
4654 const runtimeDir = fileURLToPath ( new URL ( './runtime' , import . meta. url ) )
47- console . log ( 'TOEHUNTOEUHNTUEHoT' )
55+ const templatesDir = fileURLToPath (
56+ new URL ( '../templates' , import . meta. url )
57+ )
58+
59+ // Let plugins and the user access the firebase config within the app
60+ nuxt . options . appConfig . firebaseConfig = options . config
61+
62+ if ( Object . keys ( options . config ) . length === 0 ) {
63+ throw new Error (
64+ '[VueFire]: Missing firebase config. Provide it to the VueFire module options.'
65+ )
66+ }
67+
68+ // nuxt.options.build.transpile.push(templatesDir)
4869 nuxt . options . build . transpile . push ( runtimeDir )
49- // TODO: check for individual options
70+
5071 addPlugin ( resolve ( runtimeDir , 'plugin' ) )
72+
73+ // const p = normalize(resolve(templatesDir, 'plugin.js'))
74+ // console.log('[VueFire]: adding', p)
75+ // addPluginTemplate({
76+ // src: normalize(resolve(templatesDir, 'plugin.js')),
77+
78+ // options: {
79+ // ...options,
80+ // },
81+ // })
5182 } ,
5283 } )
5384
54- export default VueFireModule
85+ export default VueFire
86+
87+ declare module '@nuxt/schema' {
88+ export interface AppConfig {
89+ /**
90+ * Firebase config to initialize the app.
91+ */
92+ firebaseConfig : FirebaseOptions
93+ }
94+ }
0 commit comments