File tree Expand file tree Collapse file tree 5 files changed +34
-6
lines changed Expand file tree Collapse file tree 5 files changed +34
-6
lines changed Original file line number Diff line number Diff line change @@ -85,6 +85,7 @@ function resolveConfig(config: Config): Context {
85
85
86
86
const defaultConfig = {
87
87
source : "src" ,
88
+ watchIgnore : [ ] ,
88
89
dist : ".scaffold/build" ,
89
90
90
91
name : "" ,
Original file line number Diff line number Diff line change @@ -62,10 +62,11 @@ export default class Serve extends Base {
62
62
* watch source dir and build when file changed
63
63
*/
64
64
async watch ( ) {
65
- const { source } = this . ctx ;
65
+ const { source, watchIgnore } = this . ctx ;
66
66
67
67
watch (
68
68
source ,
69
+ watchIgnore ,
69
70
{
70
71
onReady : async ( ) => {
71
72
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 {
76
76
77
77
watch (
78
78
[ this . ctx . source , this . ctx . test . entries ] . flat ( ) ,
79
+ this . ctx . watchIgnore ,
79
80
{
80
81
onChange : async ( path ) => {
81
82
if ( isSource ( path ) ) {
Original file line number Diff line number Diff line change @@ -7,17 +7,33 @@ import type { UpdateJSON } from "./update-json.js";
7
7
8
8
export interface Config {
9
9
/**
10
- * The source code directories.
10
+ * Source root directory or directories for the plugin .
11
11
*
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.
13
16
*
14
- * 源码目录 。
17
+ * 插件的源码根目录(可为字符串或字符串数组) 。
15
18
*
16
- * 可以是多个目录,将在 `server` 运行时监听这些目录的变更。
19
+ * 用于以下两个目的:
20
+ * - 在开发模式下监听这些目录,以便在文件变更时触发重建;
21
+ * - 在构建阶段中,用于识别 assets 所在的顶层目录,以移除该目录本身,仅将其内容复制到输出目录的根部。
17
22
*
23
+ * @example ["src", "addon"]
18
24
* @default "src"
19
25
*/
20
26
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
+
21
37
/**
22
38
* The build directories.
23
39
*
Original file line number Diff line number Diff line change @@ -2,9 +2,11 @@ import type { Stats } from "node:fs";
2
2
import chokidar from "chokidar" ;
3
3
import { debounce } from "es-toolkit" ;
4
4
import { logger } from "./logger.js" ;
5
+ import { toArray } from "./string.js" ;
5
6
6
7
export function watch (
7
8
source : string | string [ ] ,
9
+ ignore : string | string [ ] | RegExp | RegExp [ ] ,
8
10
event : {
9
11
onReady ?: ( ) => any ;
10
12
onChange : ( path : string ) => any | Promise < any > ;
@@ -13,7 +15,14 @@ export function watch(
13
15
} ,
14
16
) {
15
17
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 ,
17
26
persistent : true ,
18
27
} ) ;
19
28
You can’t perform that action at this time.
0 commit comments