Open etagwerker opened 4 years ago
I concur but I think this is not a problem in a specific Rails version, rather a version of sprockets. I took this up on the sprockets-rails repo and they decided that this is a bootstrap-sass issue for not using the sprockets-4.0.0 api correctly. Sprockets has since version 4 stopped supporting regular expressions in asset paths.
This was my bug report to sprockets-rails and for that I've set up a reproduction case example app: https://github.com/rails/sprockets-rails/issues/457
I've tried my best to try and make a PR, but all the ways I could fathom to try have failed me, relative paths, absolute paths, adding directory to config.assets.path
or adding file paths to config.assets.precompile
and variants of that.
Right now I'm adding absolute file paths to config.assets.precompile
which make sprockets deal with the files but then I get stuck on the following error instead:
Sprockets::ConversionError: could not convert "application/x-font-ttf" to nil
whenever I try to run
bundle exec rake assets:precompile --trace
My engine.rb looks like this:
module Bootstrap
module Rails
class Engine < ::Rails::Engine
...
sprockets_version = Sprockets::Rails::VERSION.split('.', 2)[0].to_i
unless sprockets_version == 3
...
end
unless sprockets_version == 4
# sprockets-rails 4 no longer support regexes for asset paths
fileendings = %w(svg ttf woff woff2)
fileendings.each do |fileending|
path = root.join("assets/fonts/glyphicons-halflings-regular.#{fileending}").to_s
uri = "file://#{path}"
app.config.assets.precompile << [uri]
end
end
end
end
end
end
Did you find a solution to this? We're running into the same issue on rails 5.2 w/sprockets 4.
I've had no problem running rails 5.2 and sprockets 4 for a while, and think this should be closed.
FYI I got here because I thought there was a sprockets 4 problem with rails 6.0 somehow (on upgrade) and investigated https://github.com/rails/sprockets-rails/issues/457 but I think that the response (https://github.com/rails/sprockets-rails/issues/457#issuecomment-575249175) was a misreading of the code (reading the sprockets < 3 targeted code as if it applied to sprockets 4).
When I debugged my situation (an error on CI) I found it was because I was issuing the precompile with different flags from issuing the test code -- ie. one was effectively using RAILS_ENV=development, resulting in (in my configuration) config.assets.digest=false
but the rspec run was resulting in config.assets.digest=true
(and I had config.assets.unknown_asset_fallback = false
, resulting in the error).
A similar situation would happen if you (somehow) precompile without digests and then run your server with them (but with config.assets.compile=false
)
As @StefanWallin linked, problem with sprockets 4, changed path handling, therefore need to help this old gem to find his fonts.
So what I did is override that @import "bootstrap_sprockets"
by making new file in overrides folder bootstrap_sprockets.scss
, with content:
@function twbs-font-path($path) {
@return $path;
}
@function twbs-image-path($path) {
@return image-path($path);
}
$bootstrap-sass-asset-helper: true;
$icon-font-path: "bootstrap/";
Using this option
Where in application.scss
file links that file with @import "bootstrap-custom";
Content of "bootstrap-custom.scss":
@import "../overrides/bootstrap_sprockets";
// Core variables and mixins
@import "bootstrap/variables";
@import "bootstrap/mixins";
// Reset and dependencies
@import "bootstrap/normalize";
@import "bootstrap/print";
@import "bootstrap/glyphicons";
// Core CSS
@import "bootstrap/scaffolding";
@import "bootstrap/type";
@import "bootstrap/code";
@import "bootstrap/grid";
@import "bootstrap/tables";
@import "bootstrap/forms";
@import "bootstrap/buttons";
// Components
@import "bootstrap/component-animations";
@import "bootstrap/dropdowns";
@import "bootstrap/button-groups";
@import "bootstrap/input-groups";
@import "bootstrap/navs";
@import "bootstrap/navbar";
@import "bootstrap/breadcrumbs";
@import "bootstrap/pagination";
@import "bootstrap/pager";
@import "bootstrap/labels";
@import "bootstrap/badges";
@import "bootstrap/jumbotron";
@import "bootstrap/thumbnails";
@import "bootstrap/alerts";
@import "bootstrap/progress-bars";
@import "bootstrap/media";
@import "bootstrap/list-group";
@import "bootstrap/panels";
@import "bootstrap/responsive-embed";
@import "bootstrap/wells";
@import "bootstrap/close";
// Components w/ JavaScript
@import "bootstrap/modals";
@import "bootstrap/tooltip";
@import "bootstrap/carousel";
// Utility classes
@import "bootstrap/utilities";
@import "bootstrap/responsive-utilities";
or just:
@import "../overrides/bootstrap_sprockets";
@import "bootstrap";
@Faq @StefanWallin I'm unconvinced that sprockets 4 + bootstrap-sass is the root problem here.
I just fixed the minimal reproduction repo's issue (thanks for creating this @StefanWallin !) by adding in @import "bootstrap-sprockets"
before importing bootstrap itself and there's no issue. https://github.com/timdiggins/sprockets-test-app/commit/a72c41bcfc0eccb9d258b7444dd062de675043e8
Here's a screenshot (but do see what happens locally if you want to -- Haven't written a test for this because life is too short 😁 ):
I just think it's worth documenting what we know can work, because then we can look for the problems elsewhere.
Hi there,
I'm running into an issue with
bootstrap-sass
:It seems that the URL is not Rails 5.1.7 friendly.
I think that a search and replace change in the paths might be necessary.
Thanks, Ernesto