Skip to content

Commit

Permalink
fix: not watch page files (umijs#1580)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yu authored and sorrycc committed Dec 7, 2018
1 parent 8e728ae commit a8909e3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
3 changes: 3 additions & 0 deletions examples/func-test/src/pages/_mock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default {
'GET /api/test': { code: 'ok' },
};
4 changes: 3 additions & 1 deletion packages/umi-build-dev/src/FilesGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { EXT_LIST } from './constants';

const debug = require('debug')('umi:FilesGenerator');

export const watcherIgnoreRegExp = /(^|[\/\\])(_mock.js$|\..)/;

export default class FilesGenerator {
constructor(opts) {
Object.keys(opts).forEach(key => {
Expand All @@ -36,7 +38,7 @@ export default class FilesGenerator {

createWatcher(path) {
const watcher = chokidar.watch(path, {
ignored: /(^|[\/\\])(_mock.js$)|(\..)/, // ignore .dotfiles and _mock.js
ignored: watcherIgnoreRegExp, // ignore .dotfiles and _mock.js
ignoreInitial: true,
});
watcher.on(
Expand Down
26 changes: 26 additions & 0 deletions packages/umi-build-dev/src/FilesGenerator.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { watcherIgnoreRegExp } from './FilesGenerator';

describe('FilesGenerator', () => {
it('watcherIgnoreRegExp', () => {
expect(
watcherIgnoreRegExp.test(
'/Users/use/code/ant/umi2/examples/func-test/src/pages/test3.js',
),
).toBe(false);
expect(
watcherIgnoreRegExp.test(
'/Users/use/code/ant/umi2/examples/func-test/src/pages/_mock.js',
),
).toBe(true);
expect(
watcherIgnoreRegExp.test(
'/Users/use/code/ant/umi2/examples/func-test/src/pages/.umi/test.js',
),
).toBe(true);
expect(
watcherIgnoreRegExp.test(
'/Users/use/code/ant/umi2/examples/func-test/src/pages/.gitignore',
),
).toBe(true);
});
});

0 comments on commit a8909e3

Please sign in to comment.