File tree 2 files changed +25
-4
lines changed
2 files changed +25
-4
lines changed Original file line number Diff line number Diff line change 1
1
import { Plugin } from "rollup"
2
2
3
- export function guardLikeWatch ( ) : Plugin {
3
+ export type Watch = {
4
+ pattern : RegExp | string
5
+ action : ( match : RegExpMatchArray , id : string ) => string [ ]
6
+ }
7
+
8
+ export function guardLikeWatch ( watches : Watch [ ] ) : Plugin {
4
9
return {
5
10
name : "vite-plugin-guard-like-watch" ,
6
11
transform ( _code , id ) {
7
- console . log ( `id:` , id )
8
- }
12
+ for ( const watch of watches ) {
13
+ const regexp = new RegExp ( watch . pattern )
14
+ const match = id . match ( regexp )
15
+ if ( match === null || match === undefined ) return
16
+
17
+ const filesToWatch = watch . action ( match , id )
18
+ for ( const file of filesToWatch ) {
19
+ this . addWatchFile ( file )
20
+ }
21
+ }
22
+ } ,
9
23
}
10
24
}
11
25
Original file line number Diff line number Diff line change @@ -12,7 +12,14 @@ export default defineConfig({
12
12
root : "." ,
13
13
projects : [ "./tsconfig.json" , "./tests/tsconfig.json" ] ,
14
14
} ) ,
15
- guardLikeWatch ( ) ,
15
+ guardLikeWatch ( [
16
+ {
17
+ pattern : / ( .* \/ e x a m p l e ) \. t s / ,
18
+ action ( match ) {
19
+ return [ `${ match [ 1 ] } .html` , `${ match [ 1 ] } .txt` ]
20
+ } ,
21
+ } ,
22
+ ] ) ,
16
23
] ,
17
24
test : {
18
25
globals : true ,
You can’t perform that action at this time.
0 commit comments