mirror of
https://github.com/facebook/docusaurus.git
synced 2025-08-04 01:09:20 +02:00
fix(v2): wait plugin watching approach (#1390)
* fix(v2): wait plugin watching approach * Update package.json * rush fix * Use 2. x branch * Update WaitPlugin.js * yarn.lock * use polling * switch chokidar w-> wait-on npm package
This commit is contained in:
parent
cb8c7125db
commit
6d53264652
4 changed files with 75 additions and 19 deletions
|
@ -5,8 +5,9 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
const fs = require('fs');
|
||||
const chokidar = require('chokidar');
|
||||
const path = require('path');
|
||||
const fs = require('fs-extra');
|
||||
const waitOn = require('wait-on');
|
||||
|
||||
class WaitPlugin {
|
||||
constructor(options) {
|
||||
|
@ -16,18 +17,20 @@ class WaitPlugin {
|
|||
apply(compiler) {
|
||||
// Before finishing the compilation step
|
||||
compiler.hooks.make.tapAsync('WaitPlugin', (compilation, callback) => {
|
||||
const {filepath} = this;
|
||||
const watcher = chokidar.watch(filepath, {
|
||||
awaitWriteFinish: true,
|
||||
disableGlobbing: true,
|
||||
});
|
||||
// To prevent 'waitOn' error on waiting non-existing directory
|
||||
fs.ensureDirSync(path.dirname(this.filepath));
|
||||
|
||||
watcher.on('add', () => {
|
||||
if (fs.existsSync(filepath)) {
|
||||
watcher.close();
|
||||
// Wait until file exist
|
||||
waitOn({
|
||||
resources: [this.filepath],
|
||||
interval: 300,
|
||||
})
|
||||
.then(() => {
|
||||
callback();
|
||||
}
|
||||
});
|
||||
})
|
||||
.catch(error => {
|
||||
console.warn(`WaitPlugin error: ${error}`);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -68,6 +68,7 @@
|
|||
"static-site-generator-webpack-plugin": "^3.4.2",
|
||||
"style-loader": "^0.22.1",
|
||||
"terser-webpack-plugin": "^1.2.3",
|
||||
"wait-on": "^3.2.0",
|
||||
"webpack": "^4.29.6",
|
||||
"webpack-bundle-analyzer": "^3.1.0",
|
||||
"webpack-dev-server": "^3.2.1",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue