csso-rails icon indicating copy to clipboard operation
csso-rails copied to clipboard

Is there a source maps support?

Open maxisoft-git opened this issue 8 years ago • 8 comments

whether it is possible to include support for the creation of source maps?

maxisoft-git avatar Mar 14 '16 14:03 maxisoft-git

With new csso itself having them now this should be possible. Will look into it

Vasfed avatar Mar 15 '16 07:03 Vasfed

in the CSSO have this opportunity but csso-rails setup this is not possible to include the generation of files, there is only the option of code restructuring.

maxisoft-git avatar Mar 15 '16 07:03 maxisoft-git

Released 0.5.0 with support for sourcemaps, please test

Vasfed avatar Mar 15 '16 23:03 Vasfed

Я обновился до 0.5.0 внес изменения в свой файл config.rb (compass) вот он


#source map
sourcemap = true

# event task for auto-prefixer and notify saved your styles #Csso.optimize
on_stylesheet_saved do |file|
  css = File.read(file)
  map = file + '.map'

  if File.exists?(map)
    result = AutoprefixerRails.process(Csso.optimize_with_sourcemap(css, map),
      from: file,
      to:   file,
      map:  { prev: File.read(map), inline: false })
    File.open(file, 'w') { |io| io << result.css }
    File.open(map,  'w') { |io| io << result.map }
  else
    File.open(file, 'w') { |io| io << Csso.optimize(AutoprefixerRails.process(css)) }
  end
end

если использовать работу без source maps все работает как и работало, если сделать поддержку генерации maps то выдает ошибку

/usr/local/bin/compass compile /Users/admin/Sites/default/themes/devkit/scss
    write /Users/admin/Sites/default/themes/devkit/assets/css/bootstrap.css
You're using ExecJS::ExternalRuntime, did you forget to add therubyracer or other execjs runtime to gemfile?
ExecJS::RuntimeError on line ["23106"] of Input.error ((execjs): CssSyntaxError: /Users/admin/Sites/default/themes/devkit/assets/css/bootstrap.css:7:91700: Missed semicolon
/*! normalize.css commit fe56763 | MIT License | github.com/necolas/normalize.css */
html{font-family:sans-serif;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%}body

maxisoft-git avatar Mar 16 '16 05:03 maxisoft-git

@maxicms optimize_with_sourcemap(input_css, input_file_name_to_put_in_map) returns array [css, map], the error you're getting is from autoprefixer (because it is being fed with invalid input).

Also it does not combine source maps in standalone, only via sprockets 4 (yep, have to run compress phase twice in current version)

So code will look like

#...
compressed_css,compressed_map = Csso.optimize_with_sourcemap(css, file)
combined_map = ... # here combine map from File.read(map) and compressed_map
result = AutoprefixerRails.process(compressed_css,
      from: file,
      to:   file,
      map:  { prev: combined_map, inline: false })

File.open(file, 'w') { |io| io << result.css }
File.open(map,  'w') { |io| io << result.map }

Vasfed avatar Mar 16 '16 19:03 Vasfed

with return parameters understood thanks, but even if you disable AutoprefixerRails then the output is optimized file in which there is no line / * # sourceMappingURL = bootstrap.css.map * /

maxisoft-git avatar Mar 17 '16 07:03 maxisoft-git

Csso handles css as strings, it has no way of knowing what the url is going to be, you have to add that line yourself

Vasfed avatar Mar 17 '16 10:03 Vasfed

very strange, as triggered by csso gulp or grunt work normally and processed at the end of a link to the css file. And in the css source code that compiles it also has a compass.

maxisoft-git avatar Mar 17 '16 10:03 maxisoft-git