diff --git a/.circleci/config.yml b/.circleci/config.yml index f8ee7985c..7d9a37f75 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -69,25 +69,25 @@ aliases: - &restore-package-node-modules-cache name: Restore cached node_modules directory keys: - - v4-package-node-modules-cache-{{ checksum "yarn.lock" }} + - v5-package-node-modules-cache-{{ checksum "yarn.lock" }} # Restore spec/dummy/node_modules dir from cache using yarn.lock checksum as a key. - &restore-dummy-app-node-modules-cache name: Restore cached spec/dummy/node_modules directory keys: - - v4-dummy-app-node-modules-cache-{{ checksum "spec/dummy/yarn.lock" }} + - v5-dummy-app-node-modules-cache-{{ checksum "spec/dummy/yarn.lock" }} # Restore vendor/bundle dir from cache using Gemfile.lock checksum as a key. - &restore-dummy-app-gem-cache name: Restore cached Ruby Gems for dummy app keys: - - v4-dummy-app-gem-cache-{{ checksum "spec/dummy/Gemfile.lock" }} + - v5-dummy-app-gem-cache-{{ checksum "spec/dummy/Gemfile.lock" }} # Restore vendor/bundle dir from cache using react_on_rails.gemspec checksum as a key. - &restore-package-gem-cache name: Restore cached Ruby Gems for package keys: - - v4-package-app-gem-cache-{{ checksum "react_on_rails.gemspec" }} + - v5-package-app-gem-cache-{{ checksum "react_on_rails.gemspec" }} # NOTE: Sometimes CI generated docker images are not updated in time to keep up with the minimum required # by chromedriver versions of Chrome. Just bump here Chrome version if chromedriver raises errors @@ -139,7 +139,7 @@ jobs: - run: *install-package-node-modules - save_cache: name: Save root node_modules to cache - key: v4-package-node-modules-cache-{{ checksum "yarn.lock" }} + key: v5-package-node-modules-cache-{{ checksum "yarn.lock" }} paths: - node_modules @@ -157,7 +157,7 @@ jobs: - run: *install-dummy-app-node-modules - save_cache: name: Save spec/dummy/node_modules to cache - key: v4-dummy-app-node-modules-cache-{{ checksum "spec/dummy/yarn.lock" }} + key: v5-dummy-app-node-modules-cache-{{ checksum "spec/dummy/yarn.lock" }} paths: - spec/dummy/node_modules - spec/dummy/node_modules @@ -172,7 +172,7 @@ jobs: - run: *install-package-ruby-gems - save_cache: name: Save dummy app ruby gems to cache - key: v4-package-app-gem-cache-{{ checksum "react_on_rails.gemspec" }} + key: v5-package-app-gem-cache-{{ checksum "react_on_rails.gemspec" }} paths: - vendor/bundle @@ -186,7 +186,7 @@ jobs: - run: *install-dummy-app-ruby-gems - save_cache: name: Save dummy app ruby gems to cache - key: v4-dummy-app-gem-cache-{{ checksum "spec/dummy/Gemfile.lock" }} + key: v5-dummy-app-gem-cache-{{ checksum "spec/dummy/Gemfile.lock" }} paths: - spec/dummy/vendor/bundle @@ -209,7 +209,7 @@ jobs: command: cd spec/dummy && yarn run build:test - save_cache: name: Save test webpack bundles to cache (for build number checksum used by rspec job) - key: v4-dummy-app-webpack-bundle-{{ .Revision }} + key: v5-dummy-app-webpack-bundle-{{ .Revision }} paths: - spec/dummy/public/webpack # Run JS unit tests for Renderer package. @@ -249,7 +249,7 @@ jobs: - restore_cache: *restore-dummy-app-gem-cache - restore_cache: name: Restore cached webpack bundles for dummy app - key: v4-dummy-app-webpack-bundle-{{ .Revision }} + key: v5-dummy-app-webpack-bundle-{{ .Revision }} - restore_cache: *restore-dummy-app-node-modules-cache - restore_cache: *restore-package-node-modules-cache - run: *install-package-node-modules diff --git a/CHANGELOG.md b/CHANGELOG.md index 004cd63f9..24bbbbd6f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,10 @@ Changes since last non-beta release. *Please add entries here for your pull requests that are not yet released.* +#### Added + +- Ability to stop React on Rails from modifying or creating the `assets:precompile` task. [PR 1371](https://github.com/shakacode/react_on_rails/pull/1371) by [justin808](https://github.com/justin808). Thanks to [elstgav](https://github.com/elstgav) for [the suggestion](https://github.com/shakacode/react_on_rails/issues/1368)! + ### [12.3.0] - 2021-07-26 #### Added diff --git a/docs/guides/how-react-on-rails-works.md b/docs/guides/how-react-on-rails-works.md index 05eb6c223..a2d087958 100644 --- a/docs/guides/how-react-on-rails-works.md +++ b/docs/guides/how-react-on-rails-works.md @@ -41,3 +41,5 @@ However, if you want to run a custom command to run webpack to build your bundle Then React on Rails modifies the `assets:precompile` task to run your `build_production_command`. If you have used the provided generator, these bundles will automatically be added to your `.gitignore` to prevent extraneous noise from re-generated code in your pull requests. You will want to do this manually if you do not use the provided generator. + +You can stop React on Rails from modifying or creating the `assets:precompile` task, by setting a `REACT_ON_RAILS_PRECOMPILE` environment variable to `no`, `false`, `n` or `f`. diff --git a/docs/rails/rails-engine-integration.md b/docs/rails/rails-engine-integration.md index c03b495b5..5d6efa065 100644 --- a/docs/rails/rails-engine-integration.md +++ b/docs/rails/rails-engine-integration.md @@ -14,24 +14,15 @@ s.add_dependency 'react_on_rails', '~> 6' ```ruby require "react_on_rails" ``` -+ In your `lib/tasks/_tasks.rake`: -```ruby -Rake.application.remove_task('react_on_rails:assets:compile_environment') - -task 'react_on_rails:assets:compile_environment' do - path = File.join(YourEngineName::Engine.root, 'client') - sh "cd #{path} && #{ReactOnRails.configuration.build_production_command}" -end -``` ## In the project including your engine Place `gem 'react_on_rails', '~> 6'` before the gem pointing at your engine in your gemfile. -This is necessary because React on Rails attaches itself to the rake assets:precompile task. It then uses a direct path to cd into client, which will not exist in the main app that includes your engine. Since you'll always be precompiling assets in the parent app, this will always fail. The workaround then, is to remove the task and replace it with one that goes into your Engine's root. The reason you have to include the react on rails gem before your engine is so that the `react_on_rails:assets:compile_environment` task is defined by the time your engine gets loaded to remove it. - Requiring `react_on_rails` and including the helper will get rid of any issues where react on rails or react_component is undefined. -As far as solving the assets issue, `lib/tasks/assets.rake` in `react_on_rails` would somehow have to know that `react_on_rails` was included in an engine, and decide the path accordingly. This might be impossible, especially in the case of multiple engines using `react_on_rails` in a single application. Another solution would be to detach this rake task from the rails assets:precompile task, and let people use it separately. +As far as solving the assets issue, `lib/tasks/assets.rake` in `react_on_rails` would somehow have to know that `react_on_rails` was included in an engine, and decide the path accordingly. This might be impossible, especially in the case of multiple engines using `react_on_rails` in a single application. + +Another solution would be to detach this rake task from the `rails assets:precompile` task. This can be done by adding `REACT_ON_RAILS_PRECOMPILE=false` to your environment. If you do so, then react assets will have to be bundled separately from `rails assets:precompile`. # Github Issues diff --git a/lib/tasks/assets.rake b/lib/tasks/assets.rake index e58925cb9..d7d285135 100644 --- a/lib/tasks/assets.rake +++ b/lib/tasks/assets.rake @@ -7,7 +7,9 @@ require "active_support" ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development" -unless ReactOnRails::WebpackerUtils.webpacker_webpack_production_config_exists? +skip_react_on_rails_precompile = %w[no false n f].include?(ENV["REACT_ON_RAILS_PRECOMPILE"]) + +if !skip_react_on_rails_precompile && !ReactOnRails::WebpackerUtils.webpacker_webpack_production_config_exists? # Ensure that rails/webpacker does not call bin/webpack if we're providing # the build command. ENV["WEBPACKER_PRECOMPILE"] = "false"