Comments (6)
Hmm, this should just work fine in development. The mtime of the file path should be checked on each lookup call.
In production, if you have cache.cache_classes
enabled in Rails. Thats a configuration in Rails that says don't automatically reload files, only reload them when I restart the entire server.
You should also check the order of the load paths. Rails.application.assets.paths
. If your gem path is before vendor/assets/javascripts
, your gem is always going to be preferred since it has a higher priority.
from sprockets.
Hey @josh, thanks for getting back to me! Here's what I've found:
Asset Paths
Asset paths look alright, I see Rails paths ahead of gem paths:
puts Rails.application.assets.paths
# /Users/rmosolgo/code/react-rails/test/dummy/app/assets/images
# /Users/rmosolgo/code/react-rails/test/dummy/app/assets/javascripts
# /Users/rmosolgo/code/react-rails/test/dummy/app/assets/stylesheets
# /Users/rmosolgo/code/react-rails/test/dummy/vendor/assets/javascripts
# /Users/rmosolgo/code/react-rails/test/dummy/vendor/assets/react
# /Users/rmosolgo/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/turbolinks-2.5.3/lib/assets/javascripts
# /Users/rmosolgo/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/es5-shim-rails-4.0.1/vendor/assets/javascripts
# /Users/rmosolgo/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/coffee-rails-4.1.0/lib/assets/javascripts
# /Users/rmosolgo/code/react-rails/lib/assets/javascripts
# /Users/rmosolgo/code/react-rails/lib/assets/react-source
# /Users/rmosolgo/code/react-rails/lib/assets/react-source/production
# /Users/rmosolgo/code/react-rails/lib/assets/javascripts
cache_classes
As for cache_classes
, someone who set this up before took care of it I think, we have this in app/config/envrionments/test.rb
:
# we need this to reload the jsx transformer when different version is dropped in
config.cache_classes = false
config.reload_plugins = true
I double-checked that our tests really run with Rails.env.test
by adding a puts Rails.env
in a test. It printed "test" as expected.
mtime
Ok, I tried overriding #fresh?
again and I had some luck. Here's what I did in a test:
# put nonsense content in the drop-in file:
app_react_file_path = File.expand_path("../dummy/vendor/assets/javascripts/react.js", __FILE__)
File.write(app_react_file_path, "'test_confirmation_token_react_content_non_production';\n")
# reload the asset (it has been loaded before, in a previous test)
react_asset = Rails.application.assets['react.js']
puts "From asset pipeline: #{File.mtime(react_asset.pathname.to_s)} (#{react_asset.pathname.to_s})"
puts "From vendor directory: #{File.mtime(app_react_file_path)} (#{app_react_file_path})"
def react_asset.fresh?(env)
puts "Testing 'fresh?'"
false
end
# reload the asset again
react_asset = Rails.application.assets['react.js']
puts "From asset pipeline: #{File.mtime(react_asset.pathname.to_s)} (#{react_asset.pathname.to_s})"
puts "From vendor directory: #{File.mtime(app_react_file_path)} (#{app_react_file_path})"
Output:
From asset pipeline: 2015-05-05 09:49:39 -0700 (/Users/rmosolgo/code/react-rails/lib/assets/react-source/development/react.js)
From vendor directory: 2015-05-14 11:53:13 -0700 (/Users/rmosolgo/code/react-rails/test/dummy/vendor/assets/javascripts/react.js)
Testing 'fresh?'
From asset pipeline: 2015-05-14 11:53:13 -0700 (/Users/rmosolgo/code/react-rails/test/dummy/vendor/assets/javascripts/react.js)
From vendor directory: 2015-05-14 11:53:13 -0700 (/Users/rmosolgo/code/react-rails/test/dummy/vendor/assets/javascripts/react.js)
So, this makes the tests pass, but not pretty!
from sprockets.
Just curious if you given Sprockets 3.x a try?
from sprockets.
rmosolgo ~/code/react-rails $ bundle show sprockets
/Users/rmosolgo/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/sprockets-3.1.0
I think that's a yes!
from sprockets.
Ok, I tried overriding #fresh? again and I had some luck. Here's what I did in a test:
Interesting, cause Asset#fresh?
doesn't exist in 3.x.
from sprockets.
Ohhhh, I'm sorry, I've left out an important part of this issue!
We're using appraisal
to test against many Rails versions (3.1 to 4.2). bundle exec appraisal test
runs the tests with a bunch of different gemfiles, this one is failing on the first one which is sprockets (2.2.3)
So that's why bundle
showed 3.x, but in fact this is failing in 2.2.3
(with Rails 3.1). And I guess that means it's actually an old Sprockets where I'm encountering this issue.
It's alright with me to just work around this! Thanks for your help and sorry I missed that before 😅
from sprockets.
Related Issues (20)
- Some assets don't get delivered anymore after update to 4.1.1 because of funky name conflict (dashes make them look like digest for the Regexp) HOT 5
- FIPS again...
- Increased Precompilation time for assets
- We cannot test on Rack 3 HOT 1
- Rails public/assets folder is not created HOT 1
- Remove Rack < 3 dependency from Sprockets HOT 1
- SCSS source maps ignores deep nesting
- rake test fails with ruby3.2.0 preview3 and onwards HOT 1
- Sprockets::CachedEnvironment is not thread-safe HOT 7
- sprockets 4.2.0 on rubygems.org HOT 2
- Sprockets compiles from "*.jpeg" to "*.jpg" that creates an error HOT 2
- Impossible to disable javascript minification
- Custom cache directory ? HOT 1
- `test_require_individual_library_files:` does not work correctly without bundler HOT 1
- Sourcemap doesn't work by default HOT 5
- Conditional `link` in manifest.js (assets.precompile discouraged)
- @import statements (such as those used for google fonts aren't positioned at the top of the css) HOT 1
- Feature suggestion: Generate webp images too by default
- sprockets does not respect the filename extension I specified in link_directory (manifest.js) in ambiguous cases
- assets:precompile & closure compressor/compiler adds debug text to javascript files HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sprockets.