[英]How to include my nodejs libraries with Google Cloud Functions
I've just made my first decent Google Cloud Function and now I'd like to refactor it into libraries.我刚刚制作了我的第一个像样的 Google Cloud Function,现在我想将它重构到库中。
Example, I've got my Cloud Function and I'd like to require a library I've created, not something installed from NPM.例如,我有我的 Cloud Function,我想要一个我创建的库,而不是从 NPM 安装的库。
How do I deploy these libraries to Google Cloud Functions?如何将这些库部署到 Google Cloud Functions?
If I understand your question correctly, you want to create a module out of your common.js
file.如果我正确理解你的问题,你想从你的
common.js
文件中创建一个模块。
If that is the case, in common.js
, export it like so:如果是这样,在
common.js
中,像这样导出它:
export default function(){
// Here is your common code
}
and then just import it into your function file:然后将其导入到您的函数文件中:
import common from './common.js';
Try using --include-node-modules
flag to include node_modules
folder with deployed sources.尝试使用 --include
--include-node-modules
标志来包含带有已部署源的node_modules
文件夹。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.