nitro
nitro copied to clipboard
Allow Function Name Customization for Firebase Build Preset
After successfully deploying Nuxt 3 to Firebase using the Nitro Firebase build preset, I noticed that the Firebase Function name generated through nuxi build
is 'server' by default.
Firebase allows its users to host multiple sites and create multiple cloud functions within a Firebase project, however, each function must be uniquely named.
Because of the build output not being customizable, to support multiple Nuxt 3 sites in the same Firebase project, I am forced to add a 'hacky' build step to update the .output/server/index.mjs
file (created by Nuxt) to rename the exported function from 'server' to a custom function name.
I have not been able to find a way to customize the function name in the build output, and it seems this is not yet supported by Nitro, and therefore is not exposed in the Nuxt config either.
I would like to request this as a feature, possibly something that could be added to the nitro.config.js
file (and ultimately the nuxt.config.js
file).
Example:
export default defineNitroConfig({
preset: 'firebase',
firebase: {
serverFunctionName: 'my-custom-function-name'
}
})
If this is already supported in any way, and I missed it, let me know. If you have questions or need more input, please let me know.
Thanks, Nitro team,
Found a similar topic here. https://github.com/nuxt/framework/discussions/2414
Because of this limitation, I have chosen to instead use the advanced node handler preset which seems to feature an unopinionated path to handing off requests to the Nitro server.
I am still hopeful that this can be implemented for the firebase preset, as it sounds like I may miss out on some features of the Firebase preset this way.
Can you share a code sample of your working nuxt and firebase configuration? Specifically a package.json
and a nuxt.config.ts
? I haven't been able to get the firebase preset working on my machine at all
As a workaround, you should be able to use rollup replace to rename your functions, see https://github.com/unjs/nitro/issues/1369 and #1257
export default defineNuxtConfig({
/* Other config options */
nitro: {
preset: "firebase",
replace: {
"export { f as server } from './chunks/nitro/": "export { f as myFunctionName } from './chunks/nitro/",
},
},
});