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

Build Production Command ignores WEBPACKER_PRECOMPILE=false #1368

Closed
elstgav opened this issue Apr 15, 2021 · 2 comments · Fixed by #1371
Closed

Build Production Command ignores WEBPACKER_PRECOMPILE=false #1368

elstgav opened this issue Apr 15, 2021 · 2 comments · Fixed by #1371

Comments

@elstgav
Copy link
Contributor

elstgav commented Apr 15, 2021

Webpacker allows you to skip compilation in the assets:precompile task if WEBPACKER_PRECOMPILE is set to false (rails/webpacker#1023). However, React on Rails will still run build_production_command.

Right now, we can manually workaround this like so:

ReactOnRails.configure do |config|
  # Copied from https://github.com/rails/webpacker/blob/7ed1c08e79c17680636fa99e6bb095ec1fbc8008/lib/tasks/webpacker/compile.rake#L36-L37
  skip_webpacker_precompile = %w[no false n f].include?(ENV["WEBPACKER_PRECOMPILE"])

  # This configures the script to run to build the production assets by webpack. Set this to nil
  # if you don't want react_on_rails building this file for you.
  unless skip_webpacker_precompile
    config.build_production_command = "RAILS_ENV=production bin/webpack"
  end
end

But it would be great if React on Rails natively supported this for feature parity 👍🏻

@justin808
Copy link
Member

@elstgav Great idea!

However, should we use the same ENV name of WEBPACKER_PRECOMPILE as there is no webpack precompile running. Instead, it's a custom command.

In terms of a fix, we can put these lines right at https://github.com/shakacode/react_on_rails/blob/master/lib/tasks/assets.rake#L10

# Compile packs after we've compiled all other assets during precompilation
skip_webpacker_precompile = %w(no false n f).include?(ENV["WEBPACKER_PRECOMPILE"])

unless skip_webpacker_precompile

@elstgav let me know if you want to create a PR or my team can do it.

@elstgav
Copy link
Contributor Author

elstgav commented Apr 20, 2021

Perhaps react on rails should have a similar ENV variable of its own, e.g. REACT_ON_RAILS_PRECOMPILE=false 🤔

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

Successfully merging a pull request may close this issue.

2 participants