简体   繁体   English

部署 Nuxt 应用时如何在 Firebase 函数中启用 Vuex

[英]How to enable Vuex in Firebase Functions when deploying Nuxt app

I'm trying to deploy a Nuxt SSR app to Firebase Functions to be served from the client and server side, everything works as expected but when trying to implement @nuxtjs/auth it works locally but not when deployed to Firebase, looking into the Firebase Functions console it says: I'm trying to deploy a Nuxt SSR app to Firebase Functions to be served from the client and server side, everything works as expected but when trying to implement @nuxtjs/auth it works locally but not when deployed to Firebase, looking into the Firebase功能控制台说:

FATAL Enable vuex store by creating store/index.js.

In my store folder I have several files for vuex spaces, I've created the index.js file there and tried with and without content but result is the same.在我的store文件夹中,我有几个用于 vuex 空间的文件,我在那里创建了 index.js 文件并尝试了有无内容,但结果是一样的。

What I do before deploying the functions is to copy the generated.nuxt folder into functions folder:我在部署函数之前所做的是将 generate.nuxt 文件夹复制到函数文件夹中:

npm run build && rm -rf functions/nuxt && cp -r .nuxt/ functions/nuxt/ && cp nuxt.config.js functions/

After that, this is the functions folder structure:之后,这是函数文件夹结构:

在此处输入图像描述

And this is the structure of nuxt folder inside functions:这是函数内部 nuxt 文件夹的结构:

在此处输入图像描述

As you can see inside the nuxt folder there is not a store folder, just a store.js file, reading it I've found it says:正如您在 nuxt 文件夹中看到的那样,没有 store 文件夹,只有一个 store.js 文件,阅读它我发现它说:

store = normalizeRoot(require('../store/index.js'), 'store/index.js')

But store folder is two folders back, in the root folder, so I've changed it to:但是存储文件夹是两个文件夹,在根文件夹中,所以我将其更改为:

store = normalizeRoot(require('../../store/index.js'), 'store/index.js')

And tried to deploy functions manually, but result is the same error message.并尝试手动部署功能,但结果是相同的错误消息。

I don't know what to do to enable Vuex in the server side of Firebase functions, I think that by changing the store.js file I could solve it, but I would need to change it in every deployment.我不知道如何在 Firebase 函数的服务器端启用 Vuex,我认为通过更改store.js文件可以解决它,但我需要在每次部署中更改它。 What is the correct way to solve it?解决它的正确方法是什么? Thanks.谢谢。

By the moment I've solved it by copying my store/ folder into functions/ folder, now the Firebase Functions console says nothing and it looks like work, but I'm not sure if it is the correct way to solve it.到现在我已经通过将我的store/文件夹复制到functions/文件夹来解决它,现在 Firebase Functions 控制台什么也没说,它看起来像工作,但我不确定它是否是解决它的正确方法。

I've changed my predeploy command to look like this:我已将我的预部署命令更改为如下所示:

rm -rf functions/nuxt && cp -r .nuxt/ functions/nuxt/ && cp nuxt.config.js functions/ && cp -r store/ functions/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM