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

React on Rails: last issue is the check for the binstubs crashes if the binstub does not exist #656

Conversation

justin808
Copy link
Contributor

@justin808 justin808 commented Aug 16, 2017

Small changes for React on Rails based on master branch of rails/webpacker

I can move the better error message part to a separate PR tomorrow.

The only issue is the check for the binstubs crashes if the binstub does not exist.

I have updated shakacode/react_on_rails#908

@justin808
Copy link
Contributor Author

@dhh @gauravtiwari I placed my one commit on top of master. Please review.

end
end

def load
if config.public_manifest_path.exist?
if config.public_manifest_path.exist? &&
(@parsed_mtime.nil? ||
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@justin808 What this does? We are already using cached timestamp

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sure we don't re-parse the JSON manifest every time for the helper. The cached timestamp is for re-compilation. React on Rails is not using the compile feature.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I follow. In production, we'll shortly have cache_manifest, so there won't be any performance penalty. In development and test, I'd be surprised if there's any big performance ding from parsing the JSON on demand as needed? This isn't going to be a huge multi-megabyte file.

@justin808 justin808 force-pushed the issue-464-merge-webpacker-lite-into-webpacker-v3 branch from dfff9de to 89a59a3 Compare August 17, 2017 08:46
Copy link
Contributor Author

@justin808 justin808 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just released React on Rails v9.0.0.beta.9 that depends on this.

@@ -5,6 +5,7 @@ default: &default
source_entry_path: packs
public_output_path: packs
cache_path: tmp/cache/webpacker
custom_compile: false
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dhh @gauravtiwari I need to add something like this so that assets:precompile does not try to use the bin/webpacker command.

We can't just turn compile off, as that's used to determine if compile checking should happen. Maybe instead of true/false, we could have a third value of "custom"? Whatever you prefer is fine with me.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I understand? Should be possible for React on Rails to overwrite the webpacker:compile task or to even remove it from the assets:precompile preconditions. I think that's probably the better move.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dhh Right now, the default precompile from both Webpacker and React on Rails is getting run. Rake is additive. I don't see a good way for React on Rails to disable to the Webpacker task. That's all I want to do.

5. Your Webpack configuration is not creating a manifest.
Your manifest contains:
#{@data.to_json}
MSG
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gauravtiwari @dhh Do we want a more detailed error message? or at least what I did on line 45 to output the manifest?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is good 👍

$stdout.puts "Using #{Webpacker.config.config_path} file for setting up webpack paths"
else
$stderr.puts "Configuration config/webpacker.yml file not found. \n"\
unless Webpacker.config.custom_compile?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that we've extracted all the logic from the rake tasks into the Webpacker classes, I think the better move here, rather than trying to hack the webpacker tasks, is probably just to have your own reactonrails:* tasks that call these Webpacker classes directly. Then you can tailor output and prerequisites as you please 👍

This fix addresses the cases where compile is disabled:

1. If React on Rails depends on Webpacker, but the React on Rails
installer has not yet generated a webpacker.yml file or a React on Rails
installation is not using Webpacker, then the gem loading of Webpacker
will crash due to the missing config file.

2. If React on Rails has its own helper to compile assets for tests,
then the manifest might need to get reloaded after Webpacker statically
loads.
Provide an easy way to tell webpacker that we have a custom compile
operation, such as used by react on rails.
@justin808 justin808 force-pushed the issue-464-merge-webpacker-lite-into-webpacker-v3 branch from 89a59a3 to ab4eb01 Compare August 18, 2017 09:01
@@ -1,7 +1,8 @@
namespace :webpacker do
desc "Verifies that bin/webpack & bin/webpack-dev-server are present."
task :check_binstubs do
unless File.exist?("bin/webpack") && File.exist?("bin/webpack-dev-server")
unless Webpacker.config.custom_compile? ||
(File.exist?("bin/webpack") && File.exist?("bin/webpack-dev-server"))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dhh @gauravtiwari How do we work around this part for React on Rails users that will not want to have the bin/webpack file installed?

It turns out that if the automatic precompile task runs, this message prints:

No compiling needed as everything is fresh

as React on Rails first does the compile, so this seems OK.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@justin808 Yeah probably should test for config/webpacker.yml since that's more primary than checking binstubs.

We discussed to remove logger output - don't think it's needed when assets are fresh.

@@ -3,14 +3,16 @@ require "webpacker/configuration"
namespace :webpacker do
desc "Verifies if webpacker is installed"
task verify_install: [:check_node, :check_yarn, :check_binstubs] do
if Webpacker.config.config_path.exist?
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The :check_binstubs is the issue, not the part below.

@justin808 justin808 changed the title configuration.rb, manifest.rb to handle no compile React on Rails: last issue is the check for the binstubs crashes if the binstub does not exist Aug 18, 2017
@gauravtiwari
Copy link
Member

We have 3 PR's open for same thing :)

@justin808 justin808 deleted the issue-464-merge-webpacker-lite-into-webpacker-v3 branch April 6, 2022 08:45
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 this pull request may close these issues.

3 participants