使用 firebase CLI 部署具有本地依赖项的 firebase 功能

Boe*_*ern 8 npm firebase google-cloud-functions yarnpkg

设置

\n

我有一个具有以下文件结构的 monorepo 设置:

\n
\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 functions\n\xe2\x94\x82   \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 src\n\xe2\x94\x82   \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 package.json\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 shared\n|   \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 dist\n|   \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 src\n|   \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 package.json\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 frontend\n|    \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 ...\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 firebase.json\n
Run Code Online (Sandbox Code Playgroud)\n

方法1(失败)

\n

./shared持有在./backend和之间共享的 TypeScript 类./frontend。理想情况下,我想使用functions/package.json符号链接引用共享库,以避免每次更改共享代码(大部分功能都位于其中)后都必须重新安装。

\n

但是,这不起作用(既不使用link:,也不使用绝对file:路径,也不使用相对file:路径)

\n
// functions/package.json\n  ...\n  "dependencies": {\n    "shared": "file:/home/boern/Desktop/wd/monorepo/shared"\n    ...\n  }\n
Run Code Online (Sandbox Code Playgroud)\n

导致错误firebase deploy --only functions( error Package "shared" refers to a non-existing file \'"home/boern/Desktop/wd/monorepo/shared"\')。库(尽管存在于 中./functions/node_modules/)未传输到服务器?

\n

方法2(失败)

\n

此外,"functions": {"ignore": []}firebase.json 中的设置也没有帮助。

\n

方法 4(可行,但缺乏要求 a)请参阅目标)

\n

唯一有效的是adevine 在 Github 上的提案:

\n
// functions/package.json\n  ...\n  "scripts": {\n     ...\n    "preinstall": "if [ -d ../shared ]; then npm pack ../shared; fi"\n  },\n  "dependencies": {\n    "shared": "file:./bbshared-1.0.0.tgz"\n    ...\n  }\n
Run Code Online (Sandbox Code Playgroud)\n

目标

\n

有人可以指出一种引用本地库的方法吗?a)./functions在开发过程中始终使用最新版本,b)使用库存 Firebase CLI 成功部署(而不是,例如使用firelink)?或者这根本不支持

\n

Boe*_*ern 2

这是我使方法 4 发挥作用的解决方法:

rm -rf ./node_modules
yarn cache clean # THIS IS IMPORTANT
yarn install
Run Code Online (Sandbox Code Playgroud)

./functions从文件夹运行它