【发布时间】:2023-01-31 14:37:43
【问题描述】:
我有一个包含 Azure Functions (TypeScript/Node) 和浏览器端代码 (TypeScript/React) 的项目。因为每个函数都有一个子目录,所以在我的存储库的根目录中定位函数是混乱和混乱的。相反,我想要一个这样的文件夹结构:
repository root
tsconfig.json
functions
examplefuncname
function.json
index.ts
shared
utilities.ts
browser
something.tsx
purejavascript.js
purejavascript.d.ts
dist
functions
examplefuncname
index.js
shared
utilitites.js
browser
something.js
purejavascript.js
purejavascript.d.ts
node_modules
...
functions 和 browser 中的 TypeScript 代码必须能够使用共享库 utilities.ts。请注意,tsc 正在将所有输出编译到顶级 dist 文件夹中。
在本地运行我的函数时,此设置工作正常。当我使用 func azure functionapp publish myappname 将它发布到 Azure 时,它似乎成功了,但门户中没有显示任何功能。我的猜测是 publish 命令只压缩 functions/ 下的文件,因此错过了 dist/。
我尝试从 tsconfig.json 中删除 outDir,以便将所有 .js 文件写入包含其 .ts 文件的目录中。这没有用,因为我有一些带有 .d.ts 文件的纯 JavaScript 文件,我收到类似“error TS5055: Cannot write file '.../server/protobuf.d.ts' 的错误,因为它会覆盖输入文件。
我尝试将我的 dist/ 文件夹移动到 server/functions 下,但这没有用,因为 node_modules 不可用,并且 node_modules 不能轻易移动。
我唯一能想到的另一件事是动态构建the folder structure wanted by Azure Functions,但这似乎很麻烦,特别是因为代码需要知道它是在本地运行还是在 App Services 中运行,以便找出文件的位置是。
【问题讨论】:
标签: azure-functions azure-functions-core-tools