diff --git a/src/frontend/AssetPreCompiler.ts b/src/frontend/AssetPreCompiler.ts index a08dd3f..fc09716 100644 --- a/src/frontend/AssetPreCompiler.ts +++ b/src/frontend/AssetPreCompiler.ts @@ -60,11 +60,6 @@ export default abstract class AssetPreCompiler { return this.assetPaths; } - public getPrimaryAssetPath(): string { - if (this.assetPaths.length === 0) throw new Error('No asset path was found.'); - return this.assetPaths[0]; - } - public abstract preCompile(canonicalName: string, alsoCompileDependents: boolean): Promise; public onPreCompile(afterPreCompileHandler: (watch: boolean) => Promise): void { @@ -101,39 +96,34 @@ export default abstract class AssetPreCompiler { } public async watch(): Promise { - this.watcher = chokidar.watch(this.getPrimaryAssetPath(), {persistent: true}); + const watchedPaths = this.assetPaths.map(p => `${p}/**/*.${this.getExtension()}`); + this.watcher = chokidar.watch(watchedPaths, {persistent: true}); this.watcher.on('ready', () => { if (!this.watcher) return; - logger.info(`Watching ${this.extension} assets for changes`); + logger.info(`Watching ${this.extension} assets for changes in ${watchedPaths}`); this.watcher.on('add', (file) => { - if (file.endsWith('.' + this.extension)) { - this.onNewFile(file) - .then(() => this.preCompile(this.toCanonicalName(file), true)) - .then(() => { - return this.afterPreCompile(true); - }) - .catch(err => logger.error(err)); - } + this.onNewFile(file) + .then(() => this.preCompile(this.toCanonicalName(file), true)) + .then(() => { + return this.afterPreCompile(true); + }) + .catch(err => logger.error(err)); }); this.watcher.on('change', (file) => { - if (file.endsWith('.' + this.extension)) { - (this.onFileChange ? this.onFileChange(file) : Promise.resolve()) - .then(() => this.preCompile(this.toCanonicalName(file), true)) - .then(() => { - return this.afterPreCompile(true); - }) - .catch(err => logger.error(err)); - } + (this.onFileChange ? this.onFileChange(file) : Promise.resolve()) + .then(() => this.preCompile(this.toCanonicalName(file), true)) + .then(() => { + return this.afterPreCompile(true); + }) + .catch(err => logger.error(err)); }); this.watcher.on('unlink', (file) => { - if (file.endsWith('.' + this.extension)) { - this.onFileRemove(file) - .catch(err => logger.error(err)); - } + this.onFileRemove(file) + .catch(err => logger.error(err)); }); }); }