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

[Feature] define hmr websocket host and port #105

Closed
wre232114 opened this issue Mar 22, 2023 · 7 comments · Fixed by #443
Closed

[Feature] define hmr websocket host and port #105

wre232114 opened this issue Mar 22, 2023 · 7 comments · Fixed by #443

Comments

@wre232114
Copy link
Member

wre232114 commented Mar 22, 2023

Currently host and port are hard coded, see https://github.com/farm-fe/farm/blob/main/packages/runtime-plugin-hmr/src/index.ts#L9

We should support using the host and port from server.hmr option. The define option would be helpful

@wre232114 wre232114 changed the title feat: define hmr websocket host and port [Feature] define hmr websocket host and port Mar 23, 2023
@Zourunfa
Copy link
Contributor

Zourunfa commented Apr 18, 2023

最近我在看这块的代码 我发现这个hmr 的port 好像是能自定义的 我打印了一下在控制台 我能问一下是不是我理解错了,搞清楚问题 然后看能不能做一下这个
Recently, I was looking at this code and I noticed that the port of this HMR seems to be customizable. I printed it on the console and wanted to ask if I misunderstood it. I need to clarify the problem and see if I can do this
image

@wre232114
Copy link
Member Author

这个是 server 部分的,是支持配置的,但是 client 的是写死的,你可以看 packages/runtime-plugin-hmr 下面的代码

@Zourunfa
Copy link
Contributor

Zourunfa commented Apr 18, 2023

image
哦 需要向webpack这样是吗,client的 在devServer下新增一个 Client配置对象,然后下面有port ,host 属性可配置

@wre232114
Copy link
Member Author

wre232114 commented Apr 19, 2023

image
配置就是这样呢,只不过这个配置没有同步到 client 那一侧。我理解加一个 define 配置就可以实现这个功能了。

define: {
  HMR_PORT: 9001
}

在 runtime plugin hmr 里面:

const port = HMR_PORT;

@Zourunfa
Copy link
Contributor

O(∩_∩)O
我是这么追溯的
先看到这个文件的绝对路径 被core下面的config的 normalizeUserCompilationConfig 方法 放在了 config.runtime.plugins里面
image

然后 整个 normalizeUserCompilationConfig 返回的 config 对象都会被 Compiler 函数编译
image

然后 我打开Compiler定义的地方,主要用到了BindingCompiler类 编译config对象
image

再看BindingCompiler类 加载的是这个了 nativeBinding = require('./farm.win32-arm64-msvc.node')
image

我推测 ./farm.win32-arm64-msvc.node 是rust生成 的 但我不知道具体代码在哪

于是我无法在packages/runtime-plugin-hmr/src/index这个文件判断从哪拿到define: {
HMR_PORT: 9001
}

希望得到大哥指教

@wre232114
Copy link
Member Author

直接在 packages/runtime-plugin-hmr/src/index 中些 const port = HMR_PORT 就好了,编译时会自动注入

@wjq990112
Copy link
Member

或许 Boolean 也需要支持一下

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 a pull request may close this issue.

3 participants