-
Notifications
You must be signed in to change notification settings - Fork 9
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
No source maps generated #23
Comments
Same issue |
Same problem here |
I’m having the same issue.
I can at least explain this: the code here calls Looking at what's happening under the hood in my install (sprockets 4.2.1, sprockets-rails 3.5.2, dartsass-sprockets 3.1.0, sassc-embedded 1.79.0), dartsass-sprockets is getting back a CSS string with a source map in it, so probably something higher up in sprockets or sprockets-rails is stripping out the comment when handling the result. |
I figured this out for my case, and it didn’t have anything to do with this gem. Other people might be having issues for a different reason. For me, the problem was that the app I’m working on used Bootstrap, and the Bootstrap gem pulls in the autoprefixer-rails gem. Even though autoprefixer-rails supports inline source maps when using it manually, it strips them out when using the Sprockets integration (and it autoregisters itself with Sprockets). If you’ve got autoprefixer-rails installed and still need inline source maps, you can remove it from Sprockets (unfortunately this means no autoprefixing 🤷). You can add this in an initializer or in Rails.application.config.assets.configure do |env|
AutoprefixerRails.uninstall(env)
end Alternatively, if you want to keep autoprefixer around…You can replace the built-in integration with one that supports inline source maps, but it’s a bit more complicated. This worked for me, but I haven’t tested extensively: # config/initializers/autoprefixer.rb
class AutoprefixerWithSourcemap < AutoprefixerRails::Sprockets
def self.run(filename, css)
output = "#{filename.chomp(File.extname(filename))}.css"
# If you want this nice an generic, you could check `css` for the presence
# of an inline source map, and set the `map` argument based on that
# instead of always setting it to `true`.
result = @processor.process(css, from: filename, to: output, map: true)
result.warnings.each do |warning|
warn "autoprefixer: #{warning}"
end
result.css
end
def self.use_bundle_processor?
::Sprockets::VERSION.to_f >= 4
end
def self.install(env)
if use_bundle_processor?
env.register_bundle_processor("text/css", self)
else
env.register_postprocessor("text/css", self)
end
end
def self.uninstall(env)
if use_bundle_processor?
env.unregister_bundle_processor("text/css", self)
else
env.unregister_postprocessor("text/css", self)
end
end
end
Rails.application.config.assets.configure do |env|
AutoprefixerRails.uninstall(env)
AutoprefixerWithSourcemap.register_processor(AutoprefixerRails.processor({}))
AutoprefixerWithSourcemap.install(env)
end I’ve also filed an issue on autoprefixer-rails if you want to follow that: ai/autoprefixer-rails#228 |
Oh wow you were spot on with that one, @Mr0grog im pretty sure that was also my situation, thank you very much |
Problem
According to the documentation, you can enable the generation of inline source maps using the following configuration:
In our case though, this does not generate any source maps in the generated
application.css
, even after removingtmp/cache
entirely. This is in development mode.Diagnosis
In
SassC::Rails::Template#config_options
, I have verified thatinline_source_maps
is indeed enabled, which in turn sets the following options:Looking at the API of
sass-embedded
, I can't find the aforementioned options though. There are the optionssource_map
andsource_map_include_sources
instead. Though enabling these does not produce a source map either.Environment
rails (7.1.3)
sprockets (3.7.2)
sprockets-rails (3.2.2)
dartsass-sprockets (3.1.0)
sassc-embedded (1.70.0)
Many thanks for your wonderful Gem and for having a look at our issue 👍
The text was updated successfully, but these errors were encountered: