我可以将 Vagrant 配置为仅在主机上存在同步文件夹时设置它吗?

Can I configure Vagrant to setup a synced folder only if it exists on the host?

对于我们的开发人员,~/Development/framework_repo 通常在主机上可用,但对于我们的设计人员而言,它不会。是否可以根据主机上的可用性有条件地配置同步文件夹?

您可以尝试使用 vagrant conditional environments. Additional reading here。 通常,您可以创建一个脚本,该脚本将在执行 vagrant up 之前成为 运行。它将测试您的环境并设置适当的 ENV 以供 vagrant 进一步使用。

由于 Vagrantfile 是一个 Ruby 脚本,您可以使用 File.directory() 检查目录是否存在,并仅在需要时启用共享文件夹。

例如:

Vagrant.configure("2") do |config|
  if File.directory?(File.expand_path("~/Development/framework_repo"))
    config.vm.synced_folder "~/Development/framework_repo", "/guest/path"
  end
end