Start a proxy server locally to cache Deno resources. The main reason is the current deno land occasionally fails to download.
deno run --allow-net --allow-read --allow-write --allow-env https://deno.land/x/deno_proxy@v1.3.1/mod.ts
Then your server will be started on http://localhost
. You can use like this:
import { VERSION } from "http://localhost/https/deno.land/std@0.140.0/version.ts";
console.log(VERSION);
It just changed your origin URL https://deno.land
to
http://localhost/https/deno.land
.
deno run --allow-read --allow-write https://deno.land/x/deno_proxy@v1.3.1/cli/mod.ts --baseUrl http://localhost:8000 --oldPath example/deps.ts --newPath example/deps_proxy.ts
If your import_map.json
like this:
{
"imports": {
"/std/": "https://deno.land/std@0.140.0/"
}
}
Then generate your proxy import_map.json
by the above:
deno run --allow-read --allow-write https://deno.land/x/deno_proxy@v1.3.1/cli/mod.ts --baseUrl http://localhost:8000 --oldPath example/import_map.json --newPath example/import_map_proxy.json
The import_map_proxy.json
should be this:
{
"imports": {
"/std/": "http://localhost:8000/https/deno.land/std@0.140.0/"
}
}
Current default will not translate the import origin in /cdn.skypack.dev/
and
/esm.sh/
. If you have to ignore your urls, you can add ignoreOrigins
such as
--ignoreOrigins /baidu.com/,/xunlei.cn/
.
Then you can run your code:
deno run -A --import-map ./example/import_map_proxy.json ./example/mod.ts
See here for more information.