|
1 | | -import { relative } from 'path' |
| 1 | +import { join, relative, resolve } from 'path' |
2 | 2 | import Debug from 'debug' |
3 | 3 | import chokidar from 'chokidar' |
4 | 4 | import { ResolvedConfig, UpdatePayload, ViteDevServer } from 'vite' |
@@ -40,17 +40,24 @@ export class Context { |
40 | 40 | : `${i}/*.${extsGlob}`, |
41 | 41 | ) |
42 | 42 |
|
| 43 | + const watchDirs = toArray(dirs).map(i => resolve(viteConfig.root, i)) |
| 44 | + const watchGlobs = toArray(watchDirs).map(i => |
| 45 | + deep |
| 46 | + ? join(i, `/**/*.${extsGlob}`) |
| 47 | + : join(i, `/*.${extsGlob}`), |
| 48 | + ) |
| 49 | + |
43 | 50 | if (viteConfig.command === 'serve') { |
44 | 51 | // TODO: use vite's watcher instead |
45 | | - chokidar.watch(dirs, { ignoreInitial: true }) |
| 52 | + chokidar.watch(watchDirs, { ignoreInitial: true }) |
46 | 53 | .on('unlink', (path) => { |
47 | | - if (matchGlobs(path, this.globs)) { |
| 54 | + if (matchGlobs(path, watchGlobs)) { |
48 | 55 | this.removeComponents(path) |
49 | 56 | this.onUpdate(path) |
50 | 57 | } |
51 | 58 | }) |
52 | 59 | .on('add', (path) => { |
53 | | - if (matchGlobs(path, this.globs)) { |
| 60 | + if (matchGlobs(path, watchGlobs)) { |
54 | 61 | this.addComponents(path) |
55 | 62 | this.onUpdate(path) |
56 | 63 | } |
|
0 commit comments