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: support config dev.liveReload #5673

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/tiny-fishes-smash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@modern-js/builder-doc': patch
'@modern-js/uni-builder': patch
---

feat: support config dev.liveReload
2 changes: 1 addition & 1 deletion packages/cli/uni-builder/src/shared/devServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const transformToRsbuildServerOptions = (
writeToDisk: (file: string) => !file.includes('.hot-update.'),
},
hot: dev?.hmr ?? true,
liveReload: true,
liveReload: dev?.liveReload ?? true,
client: {
path: '/webpack-hmr',
overlay: false,
Expand Down
6 changes: 6 additions & 0 deletions packages/document/builder-doc/docs/en/api/config-dev.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ import Hmr from '@en/config/dev/hmr.md';

<Hmr />

## dev.liveReload

import LiveReload from '@en/config/dev/live-reload.md';

<LiveReload />

## dev.host

import Host from '@en/config/dev/host.md';
Expand Down
19 changes: 19 additions & 0 deletions packages/document/builder-doc/docs/en/config/dev/live-reload.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
- **Type:** `boolean`
Copy link
Member

Choose a reason for hiding this comment

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

Please add the document to main-doc instead of builder-doc.

builder-doc is no longer maintained

Copy link
Collaborator

Choose a reason for hiding this comment

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

@2heal1 cc

- **Default:** `true`

Whether to reload the page when source files are changed.

By default, Modern.js uses HMR as the preferred method to update modules. If HMR is disabled or cannot be used in certain scenarios, it will automatically fallback to liveReload.

## Disabling liveReload

If you need to disable liveReload, you can set both `dev.hmr` and `dev.liveReload` to `false`. Then, no Web Socket requests will be made to the dev server on the page, and the page will not automatically refresh when file change.

```js
export default {
dev: {
hmr: false,
liveReload: false,
},
};
```
6 changes: 6 additions & 0 deletions packages/document/builder-doc/docs/zh/api/config-dev.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ import Hmr from '@zh/config/dev/hmr.md';

<Hmr />

## dev.liveReload

import LiveReload from '@zh/config/dev/live-reload.md';

<LiveReload />

## dev.host

import Host from '@zh/config/dev/host.md';
Expand Down
19 changes: 19 additions & 0 deletions packages/document/builder-doc/docs/zh/config/dev/live-reload.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
- **类型:** `boolean`
- **默认值:** `true`

是否在源文件变更时自动刷新页面。

默认情况下,Modern.js 会优先使用 HMR 来更新模块。当 HMR 功能被禁用,或者某些场景 HMR 无法生效时,会自动降级到 liveReload。

## 禁用 liveReload

如果你需要禁用 liveReload,可以将 `dev.hmr` 和 `dev.liveReload` 同时设置为 `false`,此时页面上不会发起 Web Socket 请求到 dev server,也不会在文件变更时自动刷新页面。

```js
export default {
dev: {
hmr: false,
liveReload: false,
},
};
```