Skip to content

Commit

Permalink
fix: Simplify installation of build dependencies by using package man…
Browse files Browse the repository at this point in the history
…ager flags
  • Loading branch information
ElMassimo committed Mar 20, 2021
1 parent ed7ccd7 commit 5c8bb62
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 29 deletions.
13 changes: 0 additions & 13 deletions vite_rails/lib/tasks/vite.rake
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,3 @@

require 'vite_ruby'
ViteRuby.install_tasks

namespace :vite_rails do
desc 'Fixes Rails management of node dev dependencies (build dependencies)'
task :set_node_env do
ENV['NODE_ENV'] = 'development'
end
end

# Set NODE_ENV before installation, so that Rails installs JS build dependencies
# on servers that precompile assets.
['yarn:install', 'webpacker:yarn_install'].each do |name|
Rake::Task[name].enhance([:'vite_rails:set_node_env']) if Rake::Task.task_defined?(name)
end
16 changes: 0 additions & 16 deletions vite_rails_legacy/lib/tasks/vite.rake
Original file line number Diff line number Diff line change
@@ -1,20 +1,4 @@
# frozen_string_literal: true

# Set NODE_ENV before installation, so that Rails installs JS build dependencies
# on servers that precompile assets.
installation_tasks = ['yarn:install', 'webpacker:yarn_install'].select { |name| Rake::Task.task_defined?(name) }.each do |name|
Rake::Task[name].enhance([:'vite_rails:set_node_env'])
end

# Ensure dependencies are installed in older versions of Rails
Rake::Task['assets:precompile']&.enhance([:'vite:install_dependencies']) if installation_tasks.none?

require 'vite_ruby'
ViteRuby.install_tasks

namespace :vite_rails do
desc 'Fixes Rails management of node dev dependencies (build dependencies)'
task :set_node_env do
ENV['NODE_ENV'] = 'development'
end
end
6 changes: 6 additions & 0 deletions vite_ruby/lib/tasks/vite.rake
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,9 @@ if Rake::Task.task_defined?('assets:precompile')
else
Rake::Task.define_task('assets:precompile' => ['vite:install_dependencies', 'vite:build'])
end

# Any prerequisite task that installs packages should also install build dependencies.
if ARGV.include?('assets:precompile')
ENV['NPM_CONFIG_PRODUCTION'] = 'false'
ENV['YARN_PRODUCTION'] = 'false'
end

0 comments on commit 5c8bb62

Please sign in to comment.