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

北城以北 提交于 2021-01-28 03:02:22

问题


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

回答1:


rsync__exclude as well as rsync__auto takes 2 _

You need to rewrite your line as

config.vm.synced_folder "./", "/home/vagrant/app", type: "rsync", rsync__auto: true, rsync__exclude: ['./node_modules*']



回答2:


Step 3 on http://perrymitchell.net/article/npm-symlinks-through-vagrant-windows/ worked better for me in the end...

From the page:

The steps are simple:

  1. Delete the node_modules directory if it exists.

  2. Create a directory called, say "node_modules_projectname" in the VM's home directory (~) (Some articles and posts recommend making the directory in /tmp, but obviously this is cleared on reboot, so it may not be an optimal experience for this type of thing).

  3. Link a local node_modules dir from within the project's directory

    ln -s ~/node_modules_projectname /path/to/your-project/node_modules

  4. Install the packages in the project directory:

    npm install



来源:https://stackoverflow.com/questions/44348807/how-to-exclude-ignore-certain-folders-in-vagrant-rsync

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!