mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-10 23:57:22 +02:00
fix(v2): fix chokidar not watching files correctly (#1340)
This commit is contained in:
parent
aa27f82acc
commit
2248b4b927
4 changed files with 26 additions and 5 deletions
|
@ -44,7 +44,11 @@ class DocusaurusPluginContentBlog {
|
|||
}
|
||||
|
||||
getPathsToWatch() {
|
||||
return [this.contentPath];
|
||||
const {include = []} = this.options;
|
||||
const globPattern = include.map(
|
||||
pattern => `${this.contentPath}/${pattern}`,
|
||||
);
|
||||
return [...globPattern];
|
||||
}
|
||||
|
||||
// Fetches blog contents and returns metadata for the contents.
|
||||
|
|
|
@ -41,7 +41,11 @@ class DocusaurusPluginContentDocs {
|
|||
}
|
||||
|
||||
getPathsToWatch() {
|
||||
return [this.contentPath, this.options.sidebarPath];
|
||||
const {include = []} = this.options;
|
||||
const globPattern = include.map(
|
||||
pattern => `${this.contentPath}/${pattern}`,
|
||||
);
|
||||
return [...globPattern, this.options.sidebarPath];
|
||||
}
|
||||
|
||||
// Fetches blog contents and returns metadata for the contents.
|
||||
|
|
|
@ -30,7 +30,11 @@ class DocusaurusPluginContentPages {
|
|||
}
|
||||
|
||||
getPathsToWatch() {
|
||||
return [this.contentPath];
|
||||
const {include = []} = this.options;
|
||||
const globPattern = include.map(
|
||||
pattern => `${this.contentPath}/${pattern}`,
|
||||
);
|
||||
return [...globPattern];
|
||||
}
|
||||
|
||||
async loadContent() {
|
||||
|
|
|
@ -41,19 +41,28 @@ module.exports = async function start(siteDir, cliOptions = {}) {
|
|||
|
||||
// Reload files processing.
|
||||
if (!cliOptions.noWatch) {
|
||||
const reload = () => {
|
||||
const reload = filepath => {
|
||||
console.log(`${filepath} has changed`);
|
||||
load(siteDir).catch(err => {
|
||||
console.error(chalk.red(err.stack));
|
||||
});
|
||||
};
|
||||
const {plugins} = props;
|
||||
|
||||
const normalizeToSiteDir = filepath => {
|
||||
if (filepath && path.isAbsolute(filepath)) {
|
||||
return path.relative(siteDir, filepath);
|
||||
}
|
||||
return filepath;
|
||||
};
|
||||
|
||||
const pluginPaths = _.compact(
|
||||
_.flatten(
|
||||
plugins.map(
|
||||
plugin => plugin.getPathsToWatch && plugin.getPathsToWatch(),
|
||||
),
|
||||
),
|
||||
);
|
||||
).map(normalizeToSiteDir);
|
||||
const fsWatcher = chokidar.watch(
|
||||
[...pluginPaths, loadConfig.configFileName],
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue