Skip to content

Commit 285bf59

Browse files
authored
fix(build): watch preprocessor dependencies during build --watch (#653)
1 parent 8d9b4f5 commit 285bf59

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

.changeset/sweet-fireants-attend.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/vite-plugin-svelte': patch
3+
---
4+
5+
fix(build): watch preprocessor dependencies during build --watch

packages/vite-plugin-svelte/src/index.ts

+10-4
Original file line numberDiff line numberDiff line change
@@ -236,10 +236,16 @@ export function svelte(inlineOptions?: Partial<Options>): Plugin[] {
236236
}
237237
logCompilerWarnings(svelteRequest, compileData.compiled.warnings, options);
238238
cache.update(compileData);
239-
if (compileData.dependencies?.length && options.server) {
240-
compileData.dependencies.forEach((d) => {
241-
ensureWatchedFile(options.server!.watcher, d, options.root);
242-
});
239+
if (compileData.dependencies?.length) {
240+
if (options.server) {
241+
for (const dep of compileData.dependencies) {
242+
ensureWatchedFile(options.server.watcher, dep, options.root);
243+
}
244+
} else if (options.isBuild && viteConfig.build.watch) {
245+
for (const dep of compileData.dependencies) {
246+
this.addWatchFile(dep);
247+
}
248+
}
243249
}
244250
log.debug(`transform returns compiled js for ${svelteRequest.filename}`);
245251
return {

0 commit comments

Comments
 (0)