diff --git a/README.md b/README.md index 57c626fe8..462aca885 100644 --- a/README.md +++ b/README.md @@ -316,9 +316,21 @@ MyApp::Application.configure do config.react.react_js = lambda {File.read(::Rails.application.assets.resolve('react.js'))} config.react.component_filenames = ['components.js'] end +``` + +#### Precompiled Component File + +The default configuration assumes the asset pipeline is available in all environments. If you precompile assets for production and want to fetch `components.js` from the precompiled assets, add this additional configuration: +```ruby +config.react.component_js = lambda do + config.react.component_filenames.map do |filename| + File.read(Rails.root.join('public', 'assets', filename)) + end.join(';') +end ``` + ## CoffeeScript It is possible to use JSX with CoffeeScript. The caveat is that you will still need to include the docblock. Since CoffeeScript doesn't allow `/* */` style comments, we need to do something a little different. We also need to embed JSX inside backticks so CoffeeScript ignores the syntax it doesn't understand. Here's an example: diff --git a/lib/react/rails/railtie.rb b/lib/react/rails/railtie.rb index 5e8d72649..fb42e3119 100644 --- a/lib/react/rails/railtie.rb +++ b/lib/react/rails/railtie.rb @@ -65,7 +65,7 @@ class Railtie < ::Rails::Railtie config.after_initialize do |app| # Server Rendering # Concat component_filenames together for server rendering - app.config.react.components_js = lambda { + app.config.react.components_js ||= lambda { app.config.react.component_filenames.map do |filename| app.assets[filename].to_s end.join(";")