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 dev.watchFiles reload-server option #6336

Merged
merged 3 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fluffy-owls-provide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@modern-js/app-tools': patch
---

feat: support dev.watchFiles reload-server option
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,19 @@ configName: dev.watchFiles
- **Type:**

```ts
type WatchFiles = {
paths: string | string[];
type?: 'reload-page' | 'reload-server';
// watch options for chokidar
options?: WatchOptions;
};
type WatchFiles =
| {
paths: string | string[];
type?: 'reload-page';
// watch options for chokidar
options?: WatchOptions;
}
| {
paths: string | string[];
type?: 'reload-server';
};

type WatchFilesConfig = WatchFiles | WatchFiles[];
```

- **Default:** `undefined`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,19 @@ configName: dev.watchFiles
- **类型:**

```ts
type WatchFiles = {
paths: string | string[];
type?: 'reload-page' | 'reload-server';
// chokidar 选项
options?: WatchOptions;
};
type WatchFiles =
| {
paths: string | string[];
type?: 'reload-page';
// chokidar 选项
options?: WatchOptions;
}
| {
paths: string | string[];
type?: 'reload-server';
};

type WatchFilesConfig = WatchFiles | WatchFiles[];
```

- **默认值:** `undefined`
Expand Down
15 changes: 14 additions & 1 deletion packages/solutions/app-tools/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import path from 'path';
import type { CliPlugin } from '@modern-js/core';
import { getLocaleLanguage } from '@modern-js/plugin-i18n/language-detector';
import { castArray } from '@modern-js/uni-builder';
import {
cleanRequireCache,
deprecatedCommands,
Expand Down Expand Up @@ -152,7 +153,19 @@ export const appTools = (
async watchFiles() {
const appContext = api.useAppContext();
const config = api.useResolvedConfigContext();
return await generateWatchFiles(appContext, config.source.configDir);
const files = await generateWatchFiles(
appContext,
config.source.configDir,
);

const watchFiles = castArray(config.dev.watchFiles);
watchFiles.forEach(({ type, paths }) => {
if (type === 'reload-server') {
files.push(...(Array.isArray(paths) ? paths : [paths]));
}
});

return files;
},

// 这里会被 core/initWatcher 监听的文件变动触发,如果是 src 目录下的文件变动,则不做 restart
Expand Down
Loading