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

Asset precompilation in the test environment uses build_production_command #1202

Closed
shepmaster opened this issue Mar 19, 2019 · 4 comments
Closed

Comments

@shepmaster
Copy link

If I run

RAILS_ENV=test bundle exec rake assets:precompile

Then the task react_on_rails:assets:webpack is run. However, this unconditionally uses build_production_command:

ReactOnRails.configuration.build_production_command

My ideal case would be for rake assets:precompile to understand the environment it is run in.

Our current workaround is to also run the webpacker task, which handles the environment correctly:

RAILS_ENV=test bundle exec rake webpacker:compile

This is unfortunate as the double compilation slows down our CI builds.

@shepmaster
Copy link
Author

shepmaster commented Mar 19, 2019

As alluded to in that file, the right solution might be to better integrate with webpacker:

if Rake::Task.task_defined?("webpacker:compile")
# TODO: Eventually, this will need reconsideration if we use any of the Webpacker compilation
Rake::Task["webpacker:compile"].clear
end

@justin808
Copy link
Member

@shepmaster The reason why the precompile task uses the production build is that I set this up for precompiling during production deploys. I was not aware that anybody would want to precompile for any other purpose. Why not just build the test bundles as part of your CI script?

@shepmaster
Copy link
Author

want to precompile for any other purpose

We have multiple parallel CI jobs. Running the first test in each of these with on-demand compilation causes the first test to fail due to long compilation times. We precompile the test assets once to:

  • avoid compiling it once per parallel instance
  • avoid the timeout on the first build

Why not just build the test bundles as part of your CI script?

Perhaps I'm misunderstanding you, but that's sort of what this issue is about.

We do build them now, but via RAILS_ENV=test bundle exec rake webpacker:compile. However, we also need to precompile normal Rails assets via assets:precompile. With the hooks from RoR here, assets:precompile also causes the production webpack assets to be built — not needed for CI.

Perhaps you can suggest another way I can state the issue; I'm not sure that I'm communicating clearly.

@justin808
Copy link
Member

@shepmaster do you need precompilation for anything other than the JS assets? If not, I'd recommend that you run the webpack build separately during your CI setup after the packages are installed. You are correct in that you don't want to build the assets for every parallel CI job. On circleci, we cache the results.

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