mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-12 00:27:21 +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() {
|
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.
|
// Fetches blog contents and returns metadata for the contents.
|
||||||
|
|
|
@ -41,7 +41,11 @@ class DocusaurusPluginContentDocs {
|
||||||
}
|
}
|
||||||
|
|
||||||
getPathsToWatch() {
|
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.
|
// Fetches blog contents and returns metadata for the contents.
|
||||||
|
|
|
@ -30,7 +30,11 @@ class DocusaurusPluginContentPages {
|
||||||
}
|
}
|
||||||
|
|
||||||
getPathsToWatch() {
|
getPathsToWatch() {
|
||||||
return [this.contentPath];
|
const {include = []} = this.options;
|
||||||
|
const globPattern = include.map(
|
||||||
|
pattern => `${this.contentPath}/${pattern}`,
|
||||||
|
);
|
||||||
|
return [...globPattern];
|
||||||
}
|
}
|
||||||
|
|
||||||
async loadContent() {
|
async loadContent() {
|
||||||
|
|
|
@ -41,19 +41,28 @@ module.exports = async function start(siteDir, cliOptions = {}) {
|
||||||
|
|
||||||
// Reload files processing.
|
// Reload files processing.
|
||||||
if (!cliOptions.noWatch) {
|
if (!cliOptions.noWatch) {
|
||||||
const reload = () => {
|
const reload = filepath => {
|
||||||
|
console.log(`${filepath} has changed`);
|
||||||
load(siteDir).catch(err => {
|
load(siteDir).catch(err => {
|
||||||
console.error(chalk.red(err.stack));
|
console.error(chalk.red(err.stack));
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
const {plugins} = props;
|
const {plugins} = props;
|
||||||
|
|
||||||
|
const normalizeToSiteDir = filepath => {
|
||||||
|
if (filepath && path.isAbsolute(filepath)) {
|
||||||
|
return path.relative(siteDir, filepath);
|
||||||
|
}
|
||||||
|
return filepath;
|
||||||
|
};
|
||||||
|
|
||||||
const pluginPaths = _.compact(
|
const pluginPaths = _.compact(
|
||||||
_.flatten(
|
_.flatten(
|
||||||
plugins.map(
|
plugins.map(
|
||||||
plugin => plugin.getPathsToWatch && plugin.getPathsToWatch(),
|
plugin => plugin.getPathsToWatch && plugin.getPathsToWatch(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
).map(normalizeToSiteDir);
|
||||||
const fsWatcher = chokidar.watch(
|
const fsWatcher = chokidar.watch(
|
||||||
[...pluginPaths, loadConfig.configFileName],
|
[...pluginPaths, loadConfig.configFileName],
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue