Skip to content

Commit

Permalink
fix: unexpect chokidar watch
Browse files Browse the repository at this point in the history
  • Loading branch information
sanyuan0704 committed Oct 12, 2022
1 parent 4ebd099 commit ad3db51
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/node/plugin-mdx/pluginMdxRollup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import pluginMdx from '@mdx-js/rollup';
import { rehypePluginPreWrapper } from './rehypePlugins/preWrapper';
import remarkPluginGFM from 'remark-gfm';
import remarkPluginFrontMatter from 'remark-frontmatter';
// @ts-expect-error The type problem of remark-directive
import remarkDirective from 'remark-directive';
import remarkPluginMDXFrontMatter from 'remark-mdx-frontmatter';
import { remarkPluginNormalizeLink } from './remarkPlugins/link';
Expand Down
4 changes: 2 additions & 2 deletions src/node/plugin-routes/RouteService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import fastGlob from 'fast-glob';
import fs from 'fs-extra';
import { RUNTIME_BUNDLE_OUTDIR } from '../constants';
import path from 'path';
import { DEFAULT_PAGE_EXTENSIONS } from '.';
import { DEFAULT_EXCLUDE, DEFAULT_PAGE_EXTENSIONS } from '.';
import { RouteOptions } from 'shared/types';

export interface RouteMeta {
Expand Down Expand Up @@ -42,7 +42,7 @@ export class RouteService {
.sync([`**/*.{${this.#extensions.join(',')}}`, ...this.#include], {
cwd: this.scanDir,
absolute: true,
ignore: ['**/node_modules/**', '**/.*', '**/dist/**', ...this.#exclude]
ignore: [...DEFAULT_EXCLUDE, ...this.#exclude]
})
.sort();
files.forEach((file) => this.addRoute(file));
Expand Down
7 changes: 6 additions & 1 deletion src/node/plugin-routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import type { ComponentType } from 'react';
import { RouteOptions } from 'shared/types/index';
import { watch } from 'chokidar';

export const DEFAULT_EXCLUDE = ['**/node_modules/**', '**/.*', '**/dist/**'];

/**
* How does the conventional route work?
* Essentially, it turns files into route object, e.g. src/pages/index.tsx -> { path: '/', element: <Index /> }
Expand Down Expand Up @@ -67,7 +69,10 @@ export function pluginRoutes(options: RouteOptions = {}): Plugin {
});
}
};
watch(scanDir)
watch(scanDir, {
ignored: [...DEFAULT_EXCLUDE, ...(options.exclude || [])],
ignoreInitial: true
})
.on('add', async (file) => {
await routeService.addRoute(file);
fileChange();
Expand Down

1 comment on commit ad3db51

@vercel
Copy link

@vercel vercel bot commented on ad3db51 Oct 12, 2022

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.