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

why watch files only in the same folder? #1480

Closed
1 of 2 tasks
franklion opened this issue Aug 29, 2018 · 7 comments
Closed
1 of 2 tasks

why watch files only in the same folder? #1480

franklion opened this issue Aug 29, 2018 · 7 comments

Comments

@franklion
Copy link

  • Operating System: MacOS High Sierra 10.13.6
  • Node Version: v8.11.0
  • NPM Version: 5.6.0
  • webpack Version: 4.8.3
  • webpack-dev-server Version: 3.1.4
  • This is a bug
  • This is a modification request

Code

// webpack-dev-server/lib/Server.js
Server.prototype._watch = function (watchPath) {
  // duplicate the same massaging of options that watchpack performs
  // https://github.com/webpack/watchpack/blob/master/lib/DirectoryWatcher.js#L49
  // this isn't an elegant solution, but we'll improve it in the future
  const usePolling = this.watchOptions.poll ? true : undefined; // eslint-disable-line no-undefined
  const interval = typeof this.watchOptions.poll === 'number' ? this.watchOptions.poll : undefined; // eslint-disable-line no-undefined
  const options = {
    ignoreInitial: true,
    persistent: true,
    followSymlinks: false,
    depth: 0,
    atomic: false,
    alwaysStat: true,
    ignorePermissionErrors: true,
    ignored: this.watchOptions.ignored,
    usePolling,
    interval
  };

  const watcher = chokidar.watch(watchPath, options).on('change', () => {
    console.log('content-changed')
    this.sockWrite(this.sockets, 'content-changed');
  });

  this.contentBaseWatchers.push(watcher);
};

Expected Behavior

I want to watch many pug files in different folders, like this src/pug/**/*.pug

Actual Behavior

It's only watching files in the same folder, like this like this src/pug/pages/*.pug or src/pug/components/*.pug

For Bugs; How can we reproduce the behavior?

For Features; What is the motivation and/or use-case for the feature?

I don't know why to set depth to 0 in the options. it is possible to modify depth to be default, then chokidar can watch files in different folders.

@michael-ciniawsky
Copy link
Member

michael-ciniawsky commented Aug 29, 2018

This instance of chokidar is for watching the content base only. Do you bundle your pug files with webpack or do you intend to serve them as static files ? webpack itself will only watch the files which are imported

@franklion
Copy link
Author

@michael-ciniawsky ok, actually I want to implement MHR, and then I have many pug pages as static files. So when I modify one of pug file, I want dev-server to reload browser. At the same time, I modify sass file, It can be Hot reload(not reload browser).

I found the same issue here (#1271).
The last developer @cloudratha commented

before(app, server) {
    server._watch(`some/path/to/watch/*/**.html`);
}

I try to implement it, but it doesn't work. because one of the options depth is 0.

before(app, server) {
    server._watch(`some/path/to/watch/*/**.pug`);
}

@glen-84
Copy link

glen-84 commented Mar 28, 2019

@evilebottnawi Closed by #1697?

@alexander-akait
Copy link
Member

@glen-84 no, we just relax depth in public directory, but developers want to watch files in other directories. I am wrong what we need major here.

@glen-84
Copy link

glen-84 commented Mar 28, 2019

@evilebottnawi You can watch in other directories, but the API is private (server._watch). The OP was asking for the depth option to be changed, and that has now been implemented.

Can you make server._watch public?

@alexander-akait
Copy link
Member

@glen-84 better do this using option

@alexander-akait
Copy link
Member

Oh, i was wrong, you can set array of contentBase and now we don't have limits so you can watch what you want

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

No branches or pull requests

4 participants