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

Ability to work without sprockets #671

Merged
merged 2 commits into from
Feb 11, 2017
Merged

Ability to work without sprockets #671

merged 2 commits into from
Feb 11, 2017

Conversation

fc-arny
Copy link
Contributor

@fc-arny fc-arny commented Jan 6, 2017

Sprockets' tasks (assets:*) not available if you do not require 'sprockets/railtie' and when you try run some rake task got a message:

ReactOnRails: Set generated_assets_dir to default: app/assets/webpack
Running via Spring preloader in process 18586
rake aborted!
Don't know how to build task 'assets:precompile' (see --tasks)
/Users/arthur/.rvm/gems/ruby-2.3.3/gems/react_on_rails-6.3.4/lib/tasks/assets.rake:35:in `<top (required)>'
...

My application config

# frozen_string_literal: true
require_relative 'boot'

require 'rails'

# Pick the frameworks you want:
require 'active_model/railtie'
require 'active_job/railtie'
require 'active_record/railtie'
require 'action_controller/railtie'
require 'action_mailer/railtie'
require 'action_view/railtie'
# require 'sprockets/railtie'

Bundler.require(*Rails.groups)

module My
  class Application < Rails::Application
    # Settings in config/environments/* take precedence over those specified here.
    # Application configuration should go into files in config/initializers
    # -- all .rb files in that directory are automatically loaded.

    config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}').to_s]
    config.i18n.default_locale = :ru
    config.i18n.enforce_available_locales = true

    config.time_zone = 'Moscow'

    config.middleware.use I18n::JS::Middleware
  end
end

This change is Reviewable

@coveralls
Copy link

coveralls commented Jan 6, 2017

Coverage Status

Coverage remained the same at 99.294% when pulling f6eaed2 on atconsulting:master into a1fe599 on shakacode:master.

@justin808
Copy link
Member

@fc-arny can you explain the use case for not using sprockets?

If you're confident others can benefit from this change, please create a changelog entry and rebase your changes on top of master. https://github.com/shakacode/react_on_rails/blob/master/CONTRIBUTING.md

@fc-arny
Copy link
Contributor Author

fc-arny commented Jan 7, 2017

@justin808 my goal is use only one tool for compiling assets.

Using webpack for compiling js, then pass bundle to application.js and then flow through sprockets' process is very slow and not transparent. Now we use react_on_rails for component rendering and https://github.com/mipearson/webpack-rails(+ stats-webpack-plugin) for inclusion code on page.

I'm not sure we need put this case in changelog. I think we can implement some ideas from webpack-rails and create better completed solution later.

@justin808
Copy link
Member

Sounds good. Please rebase your changes on top of master and get CI to pass. Please add a CHANGELOG.md entry and if possible, add some test.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 99.298% when pulling 1382a05 on atconsulting:master into f929478 on shakacode:master.

@coveralls
Copy link

coveralls commented Jan 7, 2017

Coverage Status

Coverage increased (+0.04%) to 99.339% when pulling 1382a05 on atconsulting:master into f929478 on shakacode:master.

@justin808
Copy link
Member

@fc-arny Wow, this is really great. What I'd LOVE to see is a file in the docs/additional-reading directory on how you use the github.com/mipearson/webpack-rails package with React on Rails.

How about we call the file:

docs/additional-reading/rails-without-sprockets

Are you able to create a simple test deployment to Heroku with this setup?

Please provide as much as you can regarding what you learned and I'll contribute with you.

@fc-arny
Copy link
Contributor Author

fc-arny commented Jan 7, 2017

@justin808 It's really cool! Let's start with this simple approach 👍

@justin808
Copy link
Member

@fc-arny Any progress on this one?

@fc-arny
Copy link
Contributor Author

fc-arny commented Jan 10, 2017

@justin808 in progress. Setup sample application and creating doc with this flow.

@justin808
Copy link
Member

@fc-arny I'm going to push out a new release later today. If this is ready, I'll include it.

@justin808
Copy link
Member

@fc-arny Anything I can to help with this one?

@fc-arny
Copy link
Contributor Author

fc-arny commented Jan 18, 2017

@justin808 sorry for this... just need some free time (3 days i this) and i will create sample application and documentation.

@justin808
Copy link
Member

@fc-arny I'm looking forward to this one. Let me know if I can help. Please be sure to see https://github.com/shakacode/react_on_rails/blob/master/CONTRIBUTING.md for some details like adding tests, updating the CHANGELOG.md, etc.

@justin808
Copy link
Member

@fc-arny Anything I can help you with to get this to completion?

@justin808
Copy link
Member

justin808 commented Feb 2, 2017

@fc-arny @rupurt, I'd like to know which of the approaches to advocate

  1. @fc-arny Yes, we need an example app!
  2. @rupurt If I release a beta with this one, can you try in your setup? Would it help?

@justin808
Copy link
Member

@fc-arny I just took a look at the code here. It seems safe enough. Just don't include the sprockets related code if Sprockets is not in the gemfile.

@rupurt, @robwise, @alexfedoseev Thoughts on this one?

@justin808 justin808 added this to the 6.6 milestone Feb 2, 2017
@rupurt
Copy link
Contributor

rupurt commented Feb 3, 2017

@justin808 I'd say you want a combination of both. It makes sense to guard the sprockets requires if the gem is not installed, but I would want to keep sprockets working for legacy apps so they can be gradually transitioned.

@justin808
Copy link
Member

@fc-arny Let me know if this is ready for merge, or if you had some more docs that you wanted to add.

CHANGELOG.md Outdated
@@ -4,7 +4,8 @@ All notable changes to this project's source code will be documented in this fil
Contributors: please follow the recommendations outlined at [keepachangelog.com](http://keepachangelog.com/). Please use the existing headings and styling as a guide, and add a link for the version diff at the bottom of the file. Also, please update the `Unreleased` link to compare to the latest release version.

## [Unreleased]
*Please add entries here for your pull requests.*
Copy link
Member

Choose a reason for hiding this comment

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

@fc-arny Please don't remove this line. Let me know if this is all ready for merge otherwise.

@justin808
Copy link
Member

@fc-arny Is this one ready? I'm going to do a release on Saturday.

@justin808
Copy link
Member

@fc-arny Please update to master to fix the conflict.

@justin808
Copy link
Member

:lgtm:


Reviewed 2 of 2 files at r1.
Review status: all files reviewed at latest revision, all discussions resolved, some commit checks failed.


Comments from Reviewable

@justin808 justin808 merged commit 85c6b08 into shakacode:master Feb 11, 2017
@justin808
Copy link
Member

In 6.5.1.

@coveralls
Copy link

coveralls commented Feb 11, 2017

Coverage Status

Coverage remained the same at 99.329% when pulling a04c282 on atconsulting:master into 7ad5c13 on shakacode:master.

justin808 pushed a commit that referenced this pull request Feb 11, 2017
This enables omitting Sprockets.

Sprockets'  tasks (assets:*)  not available if you do not require 'sprockets/railtie' and when you try run some rake task got a message: 
```bash
ReactOnRails: Set generated_assets_dir to default: app/assets/webpack
Running via Spring preloader in process 18586
rake aborted!
Don't know how to build task 'assets:precompile' (see --tasks)
/Users/arthur/.rvm/gems/ruby-2.3.3/gems/react_on_rails-6.3.4/lib/tasks/assets.rake:35:in `<top (required)>'
...

```
My application config

```ruby
# frozen_string_literal: true
require_relative 'boot'

require 'rails'

# Pick the frameworks you want:
require 'active_model/railtie'
require 'active_job/railtie'
require 'active_record/railtie'
require 'action_controller/railtie'
require 'action_mailer/railtie'
require 'action_view/railtie'
# require 'sprockets/railtie'

Bundler.require(*Rails.groups)

module My
  class Application < Rails::Application
    # Settings in config/environments/* take precedence over those specified here.
    # Application configuration should go into files in config/initializers
    # -- all .rb files in that directory are automatically loaded.

    config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}').to_s]
    config.i18n.default_locale = :ru
    config.i18n.enforce_available_locales = true

    config.time_zone = 'Moscow'

    config.middleware.use I18n::JS::Middleware
  end
end
```
justin808 added a commit that referenced this pull request Feb 11, 2017
…e-redux-div-to-json-script

* origin/master: (42 commits)
  Release 6.5.1
  Update CHANGELOG.md
  Ability to work without sprockets (#671)
  Change Turbolinks unmount event from before-visit to before-render (#709)
  Update generator.md
  Update README.md
  Update i18n.md
  Small formatting tweak
  Release 6.5.0
  Updated CHANGELOG.md
  Update README.md
  Update README.md
  Update README.md
  Fix incorrect "this" references of Node.js SSR
  Remove reference to heroku-buildpack-multi (#698)
  Small fixes to achieve reproducible build (#661)
  Update PROJECTS.md
  Doc Changes for links on gitbook
  Update README.md
  Added property renderedHtml to return gen func
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants