Skip to content

Capistrano Deployment

Tailwind Stylesheet Generation

For Hyvä projects deployed with capistrano-magento2, if the production stylesheet is not kept in version control, there are a few additional steps required to generate it during deployment.

Create a file named tailwind.rake in %MAGENTOPROJECTROOT%/lib/capistrano/tasks with the following content:

namespace :deploy do
    desc 'Build tailwindCSS'
    task :hyva_tailwind_build do
      on roles(:all) do
        fetch(:hyva_tailwind_paths, []).each do |tailwind_path|
          within release_path + tailwind_path do
            execute :npm, :ci
            execute :npm, :run, "build-prod"
          end
        end
      end
    end
  end
Then you need to set a variable in your config/deploy.rb file:

set :hyva_tailwind_paths, [
  'app/design/frontend/Vendor/ThemeName/web/tailwind'
]
and in the same file add the tailwind task:

before 'magento:setup:static-content:deploy', 'deploy:hyva_tailwind_build'
If you have more than one Hyva theme, you can add more paths to the variable since it is an array.

Server Requirements

To build the production stylesheet, you need to have node and npm installed on your server.

Optional: Change node version using NVM

If you need to switch node version (for i.e. using different node version then default) you can add https://github.com/koenpunt/capistrano-nvm

Add the module to the Gemfile:

gem 'capistrano-nvm', :git => 'https://github.com/koenpunt/capistrano-nvm.git', require: false

Add the module to the Capfile:

# add nvm support
require 'capistrano/nvm'

Add the settings to config/deploy.rb file:

# nvm settings
set :nvm_type, :user # or :system, depends on your nvm setup
set :nvm_node, 'v16.15.0'
#set :nvm_map_bins, %w{node npm yarn}