Skip to content
This repository has been archived by the owner on Mar 7, 2024. It is now read-only.

Commit

Permalink
fix: 修正配置文件的 watch (#951)
Browse files Browse the repository at this point in the history
  • Loading branch information
yesmeck committed May 14, 2020
1 parent fe09dbd commit 2540706
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions packages/remax-cli/src/build/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ import { Compiler } from 'webpack';
import SingleEntryPlugin from 'webpack/lib/SingleEntryPlugin';
import { getPages } from '../getEntries';

let watchCounter = 0;
let isRunning = true;

export default function watch(options: Options, compiler: Compiler, watcher: any, addEntry = false) {
watchCounter += 1;
// 监听额外的文件
const pages = getPages(options);
chokidar.watch([`${options.rootDir}/app.config.{js,ts}`]).on('change', () => {
if (watchCounter <= 1) return;
if (isRunning) return;
if (addEntry) {
const nextPages = getPages(options);
nextPages.forEach(np => {
Expand All @@ -23,10 +22,18 @@ export default function watch(options: Options, compiler: Compiler, watcher: any
watcher.invalidate();
});

chokidar.watch([`${options.rootDir}/**/*.config.{js,ts}`]).on('all', () => {
if (watchCounter <= 1) return;
chokidar.watch([`${options.rootDir}/**/!(app).config.{js,ts}`]).on('all', () => {
if (isRunning) return;
watcher.invalidate();
});

compiler.hooks.watchRun.tap('watchRun', () => {
isRunning = true;
});

compiler.hooks.done.tap('done', () => {
isRunning = false;
});

return watcher;
}

1 comment on commit 2540706

@vercel
Copy link

@vercel vercel bot commented on 2540706 May 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.