Skip to content

Commit 46bb0b5

Browse files
author
Robert Mosolgo
committed
Merge pull request #267 from byroot/set-version-from-an-initializer
Set the assets version from an initializer
2 parents b1a0755 + 9d10e9e commit 46bb0b5

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

lib/react/rails/railtie.rb

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ class Railtie < ::Rails::Railtie
2828
end
2929
end
3030

31+
initializer "react_rails.bust_cache", group: :all do |app|
32+
variant = app.config.react.variant == :production ? 'production' : 'development'
33+
variant += '-with-addons' if app.config.react.addons
34+
35+
app.assets.version = [
36+
app.assets.version,
37+
"react-#{variant}",
38+
].compact.join('-')
39+
end
40+
3141
config.before_initialize do |app|
3242
# We want to include different files in dev/prod. The development builds
3343
# contain console logging for invariants and logging to help catch
@@ -41,14 +51,6 @@ class Railtie < ::Rails::Railtie
4151
end
4252

4353
config.after_initialize do |app|
44-
variant = app.config.react.variant == :production ? 'production' : 'development'
45-
variant += '-with-addons' if app.config.react.addons
46-
47-
app.assets.version = [
48-
app.assets.version,
49-
"react-#{variant}",
50-
].compact.join('-')
51-
5254
# The class isn't accessible in the configure block, so assign it here if it wasn't overridden:
5355
app.config.react.server_renderer ||= React::ServerRendering::SprocketsRenderer
5456

0 commit comments

Comments
 (0)