-
Notifications
You must be signed in to change notification settings - Fork 393
feat: deploy on edge environment #8097
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sylingd
wants to merge
25
commits into
web-infra-dev:main
Choose a base branch
from
sylingd:feat/edge
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
+3,877
−1,105
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
🦋 Changeset detectedLatest commit: 78d9577 The changes in this PR will be included in the next version bump. This PR includes changesets to release 111 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
✅ Deploy Preview for modernjs-v3 ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
支持部署至边缘计算环境(包括腾讯云 EdgeOne、阿里云 ESA、Cloudflare Workers)(顺便修复了#7758 )
Support deploy application to edge computing environments (including Tencent EdgeOne, Alibaba Cloud ESA, and Cloudflare Workers).
Related Links
Checklist
pnpm run change.详细说明
支持了哪些平台
为什么没有在原有的 workerSSR 基础上做
有试图完善这个功能。但发现存在几个问题:
后重新考虑方案,决定基于node版本实现,原因如下:
第三方平台环境特点
运行环境
入口文件
同时,三者都有一个共同特点:会对产物进行二次打包,生成单一文件供运行。因此,会破坏原有文件结构,即使CF对fs相关API进行了兼容,也没有办法直接使用。
没有支持腾讯云EO的Edge Functions的原因是其缺失太多Node API,比如async_hooks库。实际上我最早开始尝试支持的也是它,理论上我可以改出一个我自己可以用的版本,但工作量很大且会对原有功能造成 break change,不具备通用性,所以最终放弃。
主要改动说明
依赖方式的核心改动
app-tools不改变原有产物结构。将这三个平台的产物生成入口+deps.js的方式,供其特有的打包工具二次打包。其中,deps.js会扫描所有node产物,并生成一个包含文件结构+内容的结构。在后续工具中,可以通过该结构读取依赖信息。server/core新增了 edge-function 的适配器,包含原有 node 插件的实现。plugin-bffserver/bff-core改动了 bff 插件,以适配上文提到的“deps.js”形式的依赖结构。Hono API暴露
server/core将 bindings 通过 loaderContext 暴露给用户。原因是其中包含了一些平台特有信息,如腾讯云EO的节点信息(其中包含了GeoIP地理信息、服务器节点等)、CF Workers的环境信息(用户需要通过它调用内置服务,如D1等)。其他
prod-serverapp-tools增加了相关入口server/create-request优先使用全局的fetch APIapp-tools增加了对各平台的入口及编译兼容配置app-tools复制 cjs 和 mjs 文件,避免被 rslib 编译一遍toolkit/utils在生成的 esm 产物中保留 import 语句,避免编译后出现 createRequire(此功能在阿里云ESA中不可用)toolkit/pluginserver/core在 package.json 中增加 esm 指向,以支持在编译时对相关包进行 tree shaking(否则会因为 cjs 没法 tree shaking 引入过多包,可能出现部分包不兼容、体积过大等问题)其他
为什么没有使用ndepe复制依赖,而是单独打包了一份modern-server
RSC 相关
暂未对 edge 环境实现 RSC 相关插件。主要原因:该功能似乎看起来还没做完。文档中也没有相关说明,无法测试。可以在后续该功能正式上线后再进行适配。
已经测试内容
在上述三个平台及node中对以下功能进行了简单测试:
未测试:vercel、netlify(从改动上分析不会对原有功能造成影响,因没有账号故未做实际测试)