gpt4 book ai didi

deno - 在生产中导入 deno 第三方

转载 作者:行者123 更新时间:2023-12-05 02:53:48 26 4
gpt4 key购买 nike

Deno 不使用任何像 npm 这样的包管理器,它只使用 URL 导入第三方依赖项。让我们看下面的例子:

从“https://deno.land/x/abc@v1.0.0-rc8/mod.ts”导入{Application};

生产中部署的代码是否包含 https://deno.land/x/abc@v1.0.0-rc8/mod.ts 的内容或者生产中的服务器必须发送一个请求 URL 获取第三方代码?

最佳答案

对于生产,deno 建议将您的依赖项保存到 git,如果您遵循该建议,那么您的服务器将不需要下载任何内容,因为它已经被缓存.

为此,您必须设置环境变量 DENO_DIR 以指定要下载依赖项的位置。

DENO_DIR=$PWD/vendor deno cache server.ts
# DENO_DIR=$PWD/vendor deno run server.ts

使用上述命令,server.ts 的所有依赖项都将下载到您的项目中,在 vendor/ 目录中,您可以将其提交给 git。

然后在生产服务器上,您必须将 DENO_DIR 设置为从 vendor/ 读取,而不是默认路径,这可以通过发出以下命令获得:

deno info

如果您没有将依赖项存储在您的版本控制系统中,那么 deno 将下载一次依赖项,并将它们存储到 DENO_DIR 目录中。


取自 deno manual :

但是如果 URL 的主机出现故障怎么办?源将不可用。

This, like the above, is a problem faced by any remote dependency system. Relying on external servers is convenient for development but brittle in production. Production software should always vendor its dependencies. In Node this is done by checking node_modules into source control. In Deno this is done by pointing $DENO_DIR to some project-local directory at runtime, and similarly checking that into source control:

# Download the dependencies.
DENO_DIR=./deno_dir deno cache src/deps.ts

# Make sure the variable is set for any command which invokes the cache.
DENO_DIR=./deno_dir deno test src

# Check the directory into source control.
git add -u deno_dir
git commit

关于deno - 在生产中导入 deno 第三方,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61987678/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com