Global agent to Shopify CLI for proxying


Shopify CLI 是开发 Shopify 应用和主题的重要工具,但在中国等网络受限地区使用时常遇到困难。

https://github.com/Shopify/cli/issues/3225 这个 issue 下面有非常多的反馈和方案尝试,翻到最下面发现 craigmichaelmartin 这位老哥给 CLI 加上了全局代理的配置。详细的代码可以查看这个 PR https://github.com/Shopify/cli/pull/5520。

主要是使用了 global-agent 这个库,global-agent 是一个用于在 Node.js 环境中支持全局代理的库。

添加代理

通过在环境变量中暴露以 SHOPIFY_ 为前缀的代理地址,SHOPIFY_HTTP_PROXY, SHOPIFY_HTTPS_PROXY, SHOPIFY_NO_PROXY。

目前该 PR 还处在 Draft 状态,可以通过测试快照来安装测试版:

pnpm i -g @shopify/cli@0.0.0-snapshot-20250313171017

同时作者也给出了提示:

After installing, validate the version by running just shopify in your terminal. If the versions don’t match, you might have multiple global instances installed. Use which shopify to find out which one you are running and uninstall it.

假如之前是通过 brew 安装的,需要先卸载。通过 which shopify 来查找当前版本的安装目录。

which shopify
# /Users/mike/Library/pnpm/shopify # 可执行文件
# /Users/mike/Library/pnpm/global/5/node_modules/@shopify/cli # @shopi/cli 安装目录

添加代理: export SHOPIFY_HTTPS_PROXY=http://127.0.0.1:1080 SHOPIFY_HTTP_PROXY=http://127.0.0.1:1080

或直接在 Shopify app 启动的时候添加: pnpm run dev --tunnel-url https://[YOUR_DOMAIN]:8080 SHOPIFY_HTTPS_PROXY=http://127.0.0.1:1080 SHOPIFY_HTTP_PROXY=http://127.0.0.1:1080

参考资料