@@ -21,14 +21,20 @@ class Engine < ::Rails::Engine
21
21
config . assets . precompile += config . requirejs . precompile
22
22
23
23
# Check for the `requirejs:precompile:all` top-level Rake task and run the following initialization code.
24
- Rake . application . top_level_tasks . each do |task_name |
25
- case task_name
26
- when "requirejs:precompile:all"
27
- # Enable class reloading so that Sprockets doesn't freeze the assets environment. This allows settings
28
- # for JS compression to be changes on a per-file basis.
29
- config . cache_classes = false
24
+ if defined? ( Rake . application ) && Rake . application . top_level_tasks == [ "requirejs:precompile:all" ]
25
+ # Prevent Sprockets from freezing the assets environment, which allows JS compression to be toggled on a per-
26
+ # file basis. This trick *will* fail if any of the lines linked to below change.
27
+
28
+ if ::Rails ::VERSION ::MAJOR >= 4
29
+ # For Rails 4 (see
30
+ # `https://github.com/rails/sprockets-rails/blob/v2.1.2/lib/sprockets/railtie.rb#L119-121`).
31
+ config . cache_classes = false
32
+ else
33
+ # For Rails 3 (see
34
+ # `https://github.com/rails/rails/blob/v3.2.19/actionpack/lib/sprockets/bootstrap.rb#L32-34`).
35
+ config . assets . digest = false
30
36
end
31
- end if defined? ( Rake . application )
37
+ end
32
38
33
39
manifest_directory = config . assets . manifest || File . join ( ::Rails . public_path , config . assets . prefix )
34
40
manifest_path = File . join ( manifest_directory , "rjs_manifest.yml" )
@@ -44,7 +50,7 @@ class Engine < ::Rails::Engine
44
50
end
45
51
end
46
52
47
- if ::Rails ::VERSION ::STRING >= "4.0.0"
53
+ if ::Rails ::VERSION ::MAJOR >= 4
48
54
config . after_initialize do |app |
49
55
config = app . config
50
56
rails_manifest_path = File . join ( app . root , 'public' , config . assets . prefix )
0 commit comments