Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hot Reload not working #124

Open
dampion opened this issue Mar 16, 2023 · 3 comments
Open

Hot Reload not working #124

dampion opened this issue Mar 16, 2023 · 3 comments

Comments

@dampion
Copy link

dampion commented Mar 16, 2023

My environment information as following:

OS: Ventura 13.2.1
Gitbook version: 3.2.3
CLI version: 2.3.2
npm version: 6.14.12
node version: 10.24.1

I encounter the problems below
when I run gitbook serve , which is running well
but when I edit the files, which should show the following message

Restart after change in file xxx.md

but it didn't. Nothing happened.
I need to ctrl+c to close the serve and restart the gitbook server manually.

But my colleague's (MBP BigSur 11.6.8 ) running well.
Please don't tell the difference of the intel and mac chips make this reason........

@ZouZhiLong
Copy link

Have you solved it so far

@dampion
Copy link
Author

dampion commented Mar 23, 2023

Have you solved it so far

Not yet, but I stop to use VuePress which is better.

@creamy-seas
Copy link

Came across this on my linux machine, and issue seems to be the glob patterns not matching when using the chokidar file watching library.

Reproducing

Wherever you have your global gitbook install, look for the watch.js file (for me it was ~/.gitbook/versions/3.2.3/lib/cli/watch.js) and try to hard code in the toWatch files:

var toWatch = [
        'book.json', 'book.js', '_layouts/**', 
        "content/README.md",
    ];

Although the '**/*.md' glob pattern is automatically generated, it seems that on different platforms it fails to match, and only hard wiring in "content/README.md" triggered the watcher.

Solution

One way of automating this is procedurally generating a full list of files to watch - in my case all the relevant files existed in the ./content directory, so injecting the following into the watch.js file

const fs = require('fs'); // ADDED

<-snip->

function watch(dir) {
    var d = Promise.defer();
    dir = path.resolve(dir);

    watchFolder = './content'; // ADDED
    var toWatch = [
        'book.json', 'book.js', '_layouts/**',
        ...fs.readdirSync(watchFolder).map(file => `${watchFolder}/${file}`) // ADDED
    ];

<-snip->

will have your releveant files being watched.

Of couse this is a very direct change and can probably be implemented more elegantly via plugins, but this would be the starting point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants