Skip to content

Commit

Permalink
feat: allow skipping dependency install in assets:precompile (#451)
Browse files Browse the repository at this point in the history
  • Loading branch information
josephnle committed Jun 7, 2024
1 parent 8cd06de commit 5a922b2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 3 additions & 0 deletions docs/src/guide/deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ You can disable the extension of the `assets:precompile` rake task by setting
the [`VITE_RUBY_SKIP_ASSETS_PRECOMPILE_EXTENSION`](/config/#skip-assets-precompile-extension)
environment variable to `true`.

By default, dependencies will be automatically installed as part of the `assets:precompile` extension.
Set `VITE_RUBY_SKIP_ASSETS_PRECOMPILE_INSTALL` to `true` to skip dependency installation.

## Compressing Assets 📦

Most CDN and edge service providers will automatically serve compressed assets,
Expand Down
10 changes: 8 additions & 2 deletions vite_ruby/lib/tasks/vite.rake
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,18 @@ unless ENV['VITE_RUBY_SKIP_ASSETS_PRECOMPILE_EXTENSION'] == 'true'
if Rake::Task.task_defined?('assets:precompile')
Rake::Task['assets:precompile'].enhance do |task|
prefix = task.name.split(/#|assets:precompile/).first
Rake::Task["#{ prefix }vite:install_dependencies"].invoke
unless ENV['VITE_RUBY_SKIP_ASSETS_PRECOMPILE_INSTALL'] == 'true'
Rake::Task["#{ prefix }vite:install_dependencies"].invoke
end
Rake::Task["#{ prefix }vite:build_all"].invoke
end
else
desc 'Bundle Vite assets'
Rake::Task.define_task('assets:precompile' => ['vite:install_dependencies', 'vite:build_all'])
if ENV['VITE_RUBY_SKIP_ASSETS_PRECOMPILE_INSTALL'] == 'true'
Rake::Task.define_task('assets:precompile' => 'vite:build_all')
else
Rake::Task.define_task('assets:precompile' => ['vite:install_dependencies', 'vite:build_all'])
end
end

unless Rake::Task.task_defined?('assets:clean')
Expand Down

0 comments on commit 5a922b2

Please sign in to comment.