Skip to content
This repository was archived by the owner on Jul 22, 2022. It is now read-only.

Updates README with capistrano example for symlinking node_modules/ dir #44

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,29 @@ Heroku requires `config.serve_static_files` to be enabled, so be sure to either

### Capistrano

All we need to do is add a task to run `npm install` before we compile the assets.
First, we'll want to cache your `node_modules/` directory so that each deploy doesn't need to reinstall all dependencies. You'll want to point the symlink at the location in your application's codebase that the `node_modules/` directory exists.

The following example is for a codebase that has a client side application nested in a subdirectory called `client_side/`.

```rb
# ./config/deploy.rb

before "deploy:npm_install", "deploy:symlink_node_modules_directory"

namespace :deploy do
#...

desc "Symlink node_modules directory"
task :symlink_node_modules_directory do
invoke_command "bash -c 'mkdir -p #{shared_path}/node_modules'"
invoke_command "bash -c 'ln -sf #{shared_path}/node_modules #{release_path}/client_side'"
end

#...
end
```

Next, we need to add a task to run `npm install` before we compile the assets.

The example below shows an example of using [nvm](https://github.com/creationix/nvm) (node version manager) to use the specified node version for your application.

Expand All @@ -144,10 +166,14 @@ The example below shows an example of using [nvm](https://github.com/creationix/
before "deploy:assets:precompile", "deploy:npm_install"

namespace :deploy do
#...

desc "Run npm install"
task :npm_install do
invoke_command "bash -c '. /home/deploy/.nvm/nvm.sh && cd #{release_path} && npm install'"
invoke_command "bash -c '. /home/deploy/.nvm/nvm.sh && cd #{release_path}/client_side/ && npm install'"
end

#...
end
```

Expand Down