How to exclude (ignore) certain folders in vagrant rsync?

Viewed 6172

I wish to run npm install in my vagrant virtual box.

But whenever I ran the npm install command, my rsync will execute. Since my host computer does not have node_modules installed, it simply remove the folder completely for me.

What do I need to do so that my vagrant rsync will ignore the node_modules folder?

I cannot have node_modules being rsynced into the guest machine because my host and guest are two different systems. So far my vagrantfile looks like this.

Vagrant.configure("2") do |config|
  config.vm.box = "laravel/homestead"

  config.vm.hostname = "localhost"

  config.vm.network "forwarded_port", guest: 8000, host: 8000

  config.vm.synced_folder "./", "/home/vagrant/app"

  config.vm.provider "virtualbox" do |v|
    v.name = "web2"
    v.memory = "4096"
    v.cpus = 2
    v.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/SHARE_NAME", "1"]
  end

  config.vm.synced_folder "./", "/home/vagrant/app", type: "rsync", rsync_auto: true, rsync_exclude: ['node_modules*']
  config.vm.provision :shell, path: "provision/setup.sh"

end

And I execute vagrant rsync via

vagrant rsync-auto
2 Answers
Related