Skip to content
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

feat: hot-update 文件生成放到 node_modules 下 #424

Open
wants to merge 20 commits into
base: master
Choose a base branch
from

Conversation

HiLanXiao
Copy link
Contributor

@HiLanXiao HiLanXiao commented Sep 7, 2023

  • 变更
    • 针对 hot-update 生成位置的变更
      • 调整了 hot-update 的生成路径,放到了 node_modules/.mako/hot_update 下
      • dev server 增加了对 node_modules/.mako 的托管,以继续支持对热更新文件的请求
      • okam 下的 node 服务也增了这一托管
    • 针对 devServer 的一些优化
      • 修复了 rust server 在指定 publicPath 时无法正确响应的 bug
      • 修复了 okam express 托管资源时,未增加 publicPath 前缀的 bug
      • 修复了 umi publicPath 配置被默认配置覆盖的 bug

验证:

  • e2e case:

    • image
  • rust server

    • publicPath 为 '/':
      • image
    • publicaPath 为 '/hot_update/':
      • image
  • okam node server(本地 umi 项目)

    • publicPath 为 '/':image
    • publicaPath 为 '/hot_update/':image

let to = self.context.config.output.path.join(filename);

std::fs::write(to, content).unwrap();
let hmr_dir = self.context.root.join("node_modules/.mako/hot_update");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里用 node_modules/.mako,是不是 runtime 就不需要调整了,改动可以小一点。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好像是可以的,我再调整下

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • 如果用 node_modules/.mako,runtime 还是需要改的:不放到 output 目录下了,得把 requireModule.publicPath 去掉。
  • 我这里还是保留 /hot_update 呢,感觉语义更清晰些

@HiLanXiao HiLanXiao changed the title 「WIP」feat: hot-update 文件生成放到 node_modules 下 feat: hot-update 文件生成放到 node_modules 下 Sep 11, 2023
@sorrycc
Copy link
Member

sorrycc commented Sep 11, 2023

@stormslowly review 下。

@@ -147,7 +147,7 @@ function createRuntime(makoModules, entryModuleId) {
invalidate () {},
check () {
const current_hash = requireModule.currentHash();
return fetch(`${requireModule.publicPath}${current_hash}.hot-update.json`).then((res)=>{
return fetch(`/hot_update/${current_hash}.hot-update.json`).then((res)=>{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里写死 会不会和用户的路由有冲突。业务有一个 hot_update/:id 的路由。这里可以参考下 umi 在 配置了 publicPath 这些资源是怎么 serve 的

原来 public_path 下 也可能定义 /:id

@@ -102,35 +138,12 @@ impl DevServer {
)
}
}
_ if path.starts_with("hot_update") => {
get_serve_response(static_serve_hmr.serve(req).await)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

之前 dev server 也写的仓促,有时间精力可以看下这部分有没有更加优雅的 crate 可以用。类似 express 一样 mout 。

@sorrycc
Copy link
Member

sorrycc commented Sep 18, 2023

这个 pr 先 hold,后续有冲突我来跟进。

@HiLanXiao
Copy link
Contributor Author

这个 pr 先 hold,后续有冲突我来跟进。

这块周末我又调整了下,更新了下备注

@stormslowly stormslowly deleted the feat/0906_CY branch March 25, 2024 05:24
@stormslowly stormslowly restored the feat/0906_CY branch March 25, 2024 05:40
@stormslowly stormslowly reopened this Mar 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants