Using a local editor with Vagrant

2019-07-14 05:24发布

问题:

I typically use the atom editor for any coding work and have folders on my computer with the code. After doing some updates on my Mac OS computer, some ruby gems stopped worked, rvm no longer responded and homebrew gave me a ton of trouble. I want to prevent this from happening again and figured I'd use Vagrant instead. I like it so far and it works fine, however I want to use my Atom editor nevertheless.

Normally I work on projects using gulp or grunt and they compile the files whenever any changes are made. While I have managed to connect to Vagrant with FileZilla, I have no idea how to connect atom to it. All I need is to edit the files in the Vagrant VM, as I would if they were stored in regular directories on my Mac. Any idea how to solve this?

回答1:

you can certainly use your current workflow but you do not necessarily need to connect to your vm using Filezilla or another protocol.

The best is to look at Synced Folders and synchronized your project directory. By default vagrant synchronized your current directory (where the Vagrantfile is store) to the /vagrant directory in the vm. so if you can place your project directory within the same folder, they will be automatically synchronized.

If Atom (I am not user of this editor) have a special folder where you store your project files, you can add this folder as synchronized folder. Add the following to your Vagrantfile

config.vm.synced_folder "/Users/fhenri/project/tac.local", "/project"

In my case this synchronized my host (mac os) folder /Users/fhenri/project/tac.local to the vm folder /project so whenever I make a change in this folder, I can see the exact same change from the vm.

If you use ruby and gems, it might be good to install the gem locally (within your project structure that you can share between the host and the guest) so they are automatically reflected in the 2 environments when you make a change.

When you're using gulpor grunt you would launch them from the vm, working on a synchronized folder and all the changes you will make from the mac os host would automatically be picked up on the vm. I remember when working with default Virtual box sharing folder, automatically is not flash light, you should allow a few seconds delay but still it is working.

If performance is becoming an issue, you can look at nfs synchronization type by making the change

config.vm.synced_folder "/Users/fhenri/project/tac.local", "/project", type: "nfs"

It should improve a bit