File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -85,6 +85,7 @@ function resolveConfig(config: Config): Context {
8585
8686const defaultConfig = {
8787 source : "src" ,
88+ watchIgnore : [ ] ,
8889 dist : ".scaffold/build" ,
8990
9091 name : "" ,
Original file line number Diff line number Diff line change @@ -62,10 +62,11 @@ export default class Serve extends Base {
6262 * watch source dir and build when file changed
6363 */
6464 async watch ( ) {
65- const { source } = this . ctx ;
65+ const { source, watchIgnore } = this . ctx ;
6666
6767 watch (
6868 source ,
69+ watchIgnore ,
6970 {
7071 onReady : async ( ) => {
7172 await this . ctx . hooks . callHook ( "serve:ready" , this . ctx ) ;
Original file line number Diff line number Diff line change @@ -76,6 +76,7 @@ export default class Test extends Base {
7676
7777 watch (
7878 [ this . ctx . source , this . ctx . test . entries ] . flat ( ) ,
79+ this . ctx . watchIgnore ,
7980 {
8081 onChange : async ( path ) => {
8182 if ( isSource ( path ) ) {
Original file line number Diff line number Diff line change @@ -7,17 +7,33 @@ import type { UpdateJSON } from "./update-json.js";
77
88export interface Config {
99 /**
10- * The source code directories.
10+ * Source root directory or directories for the plugin .
1111 *
12- * Can be multiple directories, and changes to these directories will be watched when `server` is running.
12+ * These paths are:
13+ * - Watched during development to trigger rebuilds on changes.
14+ * - Used to remove the top-level asset directory (e.g. `assets/`) during build,
15+ * so that only its contents are copied directly to the output root.
1316 *
14- * 源码目录 。
17+ * 插件的源码根目录(可为字符串或字符串数组) 。
1518 *
16- * 可以是多个目录,将在 `server` 运行时监听这些目录的变更。
19+ * 用于以下两个目的:
20+ * - 在开发模式下监听这些目录,以便在文件变更时触发重建;
21+ * - 在构建阶段中,用于识别 assets 所在的顶层目录,以移除该目录本身,仅将其内容复制到输出目录的根部。
1722 *
23+ * @example ["src", "addon"]
1824 * @default "src"
1925 */
2026 source : string | string [ ] ;
27+
28+ /**
29+ * The files to ignore when watching.
30+ *
31+ * 忽略的监听文件。
32+ *
33+ * @default []
34+ */
35+ watchIgnore : string | string [ ] | RegExp | RegExp [ ] ;
36+
2137 /**
2238 * The build directories.
2339 *
Original file line number Diff line number Diff line change @@ -2,9 +2,11 @@ import type { Stats } from "node:fs";
22import chokidar from "chokidar" ;
33import { debounce } from "es-toolkit" ;
44import { logger } from "./logger.js" ;
5+ import { toArray } from "./string.js" ;
56
67export function watch (
78 source : string | string [ ] ,
9+ ignore : string | string [ ] | RegExp | RegExp [ ] ,
810 event : {
911 onReady ?: ( ) => any ;
1012 onChange : ( path : string ) => any | Promise < any > ;
@@ -13,7 +15,14 @@ export function watch(
1315 } ,
1416) {
1517 const watcher = chokidar . watch ( source , {
16- ignored : / ( ^ | [ / \\ ] ) \. ./ , // ignore dotfiles
18+ ignored : [
19+ / ( ^ | [ / \\ ] ) \. ./ , // ignore dotfiles
20+ / [ \\ / ] \. g i t [ \\ / ] / ,
21+ / [ \\ / ] n o d e _ m o d u l e s [ \\ / ] / ,
22+ ...toArray ( ignore ) ,
23+ ] ,
24+ ignoreInitial : true ,
25+ ignorePermissionErrors : true ,
1726 persistent : true ,
1827 } ) ;
1928
You can’t perform that action at this time.
0 commit comments