Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add precompile hook #491

Open
justin808 opened this issue Jun 8, 2024 · 1 comment
Open

Add precompile hook #491

justin808 opened this issue Jun 8, 2024 · 1 comment

Comments

@justin808
Copy link
Member

Sometimes, we always want to run some code, like

rake react_on_rails:generate_packs

whenever about to run webpack

We can add a shakapacker.yml configuration so some code can run before invoking the webpack.

precompile_hook: rake react_on_rails:generate_packs

This way, "it just works" in terms of having some files ready that React on Rails needs.

Alternatives:

  • While we could modify the installed bin files, that can make upgrades trickier
  • We could wrap the bin files with new scripts.
@G-Rath
Copy link
Contributor

G-Rath commented Jun 8, 2024

You should already be able to do this with Rake:

# lib/tasks/assets.rake
namespace :assets do
  desc "Ensures that dependencies required to compile assets are installed"
  task install_dependencies: :environment do
    raise if File.exist?("package-lock.json") && !(system "npm install")
  end
end

Rake::Task["assets:precompile"].enhance ["assets:install_dependencies"]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants