Skip to content
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

Update css source map when adding prefixes #202

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 28 additions & 3 deletions lib/autoprefixer-rails/sprockets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,34 @@ def self.register_processor(processor)

# Sprockets 3 and 4 API
def self.call(input)
filename = input[:filename]
source = input[:data]
run(filename, source)
filename = input[:filename]
source = input[:data]
previous_map = input[:metadata] && input[:metadata][:map]

output = filename.chomp(File.extname(filename)) + ".css"
map_param = previous_map ? {
inline: false, # do not generate inline source map
prev: false, # omit previous source map if embedded in source css
annotation: false, # do not append source map comment to css
sourcesContent: false,
} : nil
result = @processor.process(source, from: filename, to: output, map: map_param)

result.warnings.each do |warning|
warn "autoprefixer: #{warning}"
end

css = result.css
map = result.map && JSON.parse(result.map)
if previous_map && map
# map = ::Sprockets::SourceMapUtils.format_source_map(map, input)
map = ::Sprockets::SourceMapUtils.combine_source_maps previous_map, map
end

{
data: css,
map: map || previous_map,
}
end

# Add prefixes to `css`
Expand Down