Skip to content

Commit 93e12ae

Browse files
authored
feat: support watch mode in modern build (#6470)
1 parent b5c8b8c commit 93e12ae

File tree

8 files changed

+14
-1
lines changed

8 files changed

+14
-1
lines changed

.changeset/thick-fans-protect.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@modern-js/app-tools': patch
3+
---
4+
5+
feat: support watch mode in modern build

packages/document/main-doc/docs/en/apis/app/commands.mdx

+1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ Usage: modern build [options]
7878
Options:
7979
-c --config <config> specify the configuration file, which can be a relative or absolute path
8080
-h, --help show command help
81+
-w --watch turn on watch mode, watch for changes and rebuild
8182
--analyze analyze the bundle and view size of each module
8283
```
8384

packages/document/main-doc/docs/zh/apis/app/commands.mdx

+1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ Usage: modern build [options]
7878
Options:
7979
-c --config <config> 指定配置文件路径,可以为相对路径或绝对路径
8080
-h, --help 显示命令帮助
81+
-w --watch 开启 watch 模式, 监听文件变更并重新构建
8182
--analyze 分析构建产物体积,查看各个模块打包后的大小
8283
```
8384

packages/solutions/app-tools/src/commands/build.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -83,5 +83,7 @@ export const build = async (
8383
'Expect the Builder to have been initialized, But the appContext.builder received `undefined`',
8484
);
8585
}
86-
await appContext.builder.build();
86+
await appContext.builder.build({
87+
watch: options?.watch,
88+
});
8789
};

packages/solutions/app-tools/src/commands/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export const buildCommand = async (
6363
.description(i18n.t(localeKeys.command.build.describe))
6464
.option('-c --config <config>', i18n.t(localeKeys.command.shared.config))
6565
.option('--analyze', i18n.t(localeKeys.command.shared.analyze))
66+
.option('-w --watch', i18n.t(localeKeys.command.build.watch))
6667
.action(async (options: BuildOptions) => {
6768
const { build } = await import('./build.js');
6869
await build(api, options);

packages/solutions/app-tools/src/locale/en.ts

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export const EN_LOCALE = {
1717
},
1818
build: {
1919
describe: 'build the app for production',
20+
watch: 'turn on watch mode, watch for changes and rebuild',
2021
},
2122
serve: { describe: 'preview the production build locally' },
2223
deploy: { describe: 'deploy the application' },

packages/solutions/app-tools/src/locale/zh.ts

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export const ZH_LOCALE = {
1616
},
1717
build: {
1818
describe: '构建生产环境产物',
19+
watch: '开启 watch 模式, 监听文件变更并重新构建',
1920
},
2021
serve: { describe: '启动生产环境服务' },
2122
deploy: { describe: '部署应用' },

packages/solutions/app-tools/src/utils/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export type DevOptions = {
88
export type BuildOptions = {
99
config?: string;
1010
analyze?: boolean;
11+
watch?: boolean;
1112
};
1213

1314
export type DeployOptions = {

0 commit comments

Comments
 (0)