1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/railties/lib/rails/tasks/yarn.rake
printercu 8e9186d241 Respect NODE_ENV when running rails yarn:install
`yarn install --prod` removes dev deps,
so it's impossible to run `assets:precompile` with dev npm dependencies.
This change makes rake task pass NODE_ENV to yarn when explicitly set.
2018-04-23 20:37:26 +03:00

19 lines
712 B
Ruby

# frozen_string_literal: true
namespace :yarn do
desc "Install all JavaScript dependencies as specified via Yarn"
task :install do
# Install only production deps when for not usual envs.
valid_node_envs = %w[test development production]
node_env = ENV.fetch("NODE_ENV") do
rails_env = ENV["RAILS_ENV"]
valid_node_envs.include?(rails_env) ? rails_env : "production"
end
system({ "NODE_ENV" => node_env }, "./bin/yarn install --no-progress --frozen-lockfile")
end
end
# Run Yarn prior to Sprockets assets precompilation, so dependencies are available for use.
if Rake::Task.task_defined?("assets:precompile")
Rake::Task["assets:precompile"].enhance [ "yarn:install" ]
end