air-verse / air

☁️ Live reload for Go apps
GNU General Public License v3.0
18.29k stars 815 forks source link

Exclude dir not working #678

Open herzadinata opened 2 weeks ago

herzadinata commented 2 weeks ago

I use: air v1.61.1, built with Go go1.23.2

This is my .air.toml file, put in the project root: Screenshot 2024-11-04 at 09 58 32

But the node_modules dir in the project root is still being watched: Screenshot 2024-11-04 at 09 57 20

Expectation: The node_modules should not be watched

istyf commented 2 weeks ago

Hmm, "works on my machine". Are you sure that it is actually using that config file? Does it fail as expected if you change the build command to some nonsense such as go build -o ./tmp/main ./nosuchdirectory ?

herzadinata commented 2 weeks ago

@istyf

Oh sorry, a little misunderstanding, i am not using it to build golang binary file, rather to watch / hot-reload my golang development environment.

...
[build]
  args_bin = []
  bin = "./tmp/main"
  cmd = "go build -o ./tmp/main ."
  exclude_dir = ["tmp", "node_modules"]
...

So that is for excluding directory on build command? That's not what I want to do.

I want to watch the changes on my golang project but excluding that node_modules from being watched. So I tried to change the code above to this

...
root = "."
tmp_dir = "tmp"
exclude_dir = ["tmp", "node_modules"]

[build]
  args_bin = []
...

That's still not excluding node_modules from being watched. Is it capable of doing that?

istyf commented 2 weeks ago

No, it is not specific to the build command. It specifies what directories should be excluded from watching for changes.

What do you want to happen when air detects a file change? What is supposed to be reloaded and how?

istyf commented 2 weeks ago

Sorry, I didn’t notice that you moved exclude_dir out of the [build] section. That does not work.

If you remove lines from the toml those settings will be set to their default values, which aren’t necessarily empty. You need to change it back to have any hope of getting it to work.

If you do not want to build anything you need to set cmd to something that succeeds but does nothing. One example is here: https://github.com/air-verse/air/issues/632#issuecomment-2315259975

herzadinata commented 2 weeks ago

@istyf I meant building I don't want to build binary file for production, but building the binary file into tmp_dir for watching purpose is is fine.

Okay so I changed back the exclude_dir: Screenshot 2024-11-06 at 09 10 37

Then run air by also pointing the air.toml. file: Screenshot 2024-11-06 at 09 10 51

But still the node_modules is being watched: Screenshot 2024-11-06 at 09 11 40

I am expecting the node_modules should not be watched as I specified in the exclude_dir above.