Skip to content

Set the assets version from an initializer #267

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

Merged
merged 1 commit into from
May 16, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions lib/react/rails/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ class Railtie < ::Rails::Railtie
end
end

initializer "react_rails.bust_cache", group: :all do |app|
variant = app.config.react.variant == :production ? 'production' : 'development'
variant += '-with-addons' if app.config.react.addons

app.assets.version = [
app.assets.version,
"react-#{variant}",
].compact.join('-')
end

config.before_initialize do |app|
# We want to include different files in dev/prod. The development builds
# contain console logging for invariants and logging to help catch
Expand All @@ -41,14 +51,6 @@ class Railtie < ::Rails::Railtie
end

config.after_initialize do |app|
variant = app.config.react.variant == :production ? 'production' : 'development'
variant += '-with-addons' if app.config.react.addons

app.assets.version = [
app.assets.version,
"react-#{variant}",
].compact.join('-')

# The class isn't accessible in the configure block, so assign it here if it wasn't overridden:
app.config.react.server_renderer ||= React::ServerRendering::SprocketsRenderer

Expand Down