kmagiera / babel-watch

Reload your babel-node app on JS source file changes. And do it fast.
MIT License
529 stars 70 forks source link

Watcher is still initialized for files that are ignored #121

Closed puchm closed 3 years ago

puchm commented 3 years ago

Hi, I noticed that --exclude is far superior to --ignore in terms of startup performance. This is the startup command I used:

babel-watch --use-polling --watch /app --ignore node_modules --extensions .ts,.graphql src/main.ts

It all works once it starts up but it always takes about a minute to do so. I tried switching --ignore node_modules to --exclude /app/node_modules (which is the absolute path to my node_modules folder) and this improved it to about 10 seconds.

I looked into the source code and I think I know what is going on:

The watcher gets started on all files except what's inside --exclude (see this line). I think anything that matches --ignore should also be excluded. This way it wont start watchers on the whole node_modules folder if the user makes use of --ignore instead of --exclude.

If that is not possible it should be communicated clearly in the readme that --exclude is better in terms of startup performance and what is the difference between --exclude and --ignore (to be honest, I don't fully understand it). Also, the node_modules folder should be the default for the --exclude option rather than the --ignore option.

Thank you for improving this in advance! Moritz

STRML commented 3 years ago

Hey, thanks. I don't think this is intentional. I believe the intention was to have the server restart on some file changes (like assets that may be cached), but not trigger babel. It doesn't seem that this is really usable for that purpose.

I haven't had time to dig through it, maybe you have, but I would consider renaming or repurposing some of these flags.

puchm commented 3 years ago

Just noticed this issue is still open. I don't have a lot of time to dig into this other than renaming these flags.

What is the difference between --ignore and --exclude?

If someone can explain that to me I could try to come up with more appropriate names or put an explanation into the readme.

STRML commented 3 years ago

So:

I don't actually see a good use case for --ignore because I assume that if you actually have this need, you already have it set in your babel config. There shouldn't be a need for a unique ignore list only when using babel-watch, but perhaps someone else has a different idea?

puchm commented 3 years ago

In this case I think the names are actually quite fitting. How about adding this explanation to the readme?

STRML commented 3 years ago

It's technically already there, but not super clear, so I'll add an additional note.