Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which output styles remove multiline line comments?

Tags:

comments

sass

In an SCSS file, which output style(s) (nested, expanded, compact or compressed) will remove multiline (/* I'm a comment. */) comments from the final CSS?

like image 569
KatieK Avatar asked May 30 '13 19:05

KatieK


3 Answers

:compressed is the only output style which will remove multi-line (/* ... */) comments from the final rendered CSS.

Additionally, :compact will turn a multi-line comment into a single line in the final CSS. With :nested and :expanded, all multi-line comments and their line breaks are rendered in the final CSS.

For example, this SCSS:

// SL Comment

/* ML Comment1
   Whoop. */

//! SL w/ bang

/*! ML Comment2
    Whoop. */

will become the following CSS for each different output style:

Nested:

/* ML Comment1
   Whoop. */
/* ML Comment2  
    Whoop. */

Expanded:

/* ML Comment1
   Whoop. */
/* ML Comment2
    Whoop. */

Compact:

/* ML Comment1 Whoop. */
/* ML Comment2 
    Whoop. */

Compressed:

/* ML Comment2
    Whoop. */

Beginning a comment with ! only affects multi-line comments in :compressed mode, where they will be preserved when they would otherwise be removed from the final CSS.

like image 144
KatieK Avatar answered Nov 15 '22 06:11

KatieK


Even with output style "compressed", I have not been able to remove multi-line comments, and the sass/scss documentation also suggests that they are not removed (only single-line comments with "//" are removed).

My solution was to simply apply a Perl one-liner to manually remove comments from a .css file, after sass has generated its final output:

sass -fCE utf-8 -t compressed application.sass application.css
perl -pi -e'BEGIN{$/=undef}s#/\*.*?\*/##gs' application.css
like image 36
Dev Avatar answered Nov 15 '22 04:11

Dev


It's a shame I can't downvote or comment on the accepted answer. As per the doc's, what was written and accepted is simply untrue. Sass only removes single line codes and preserves multiline comments.

Sass supports standard multiline CSS comments with /* */, as well as single-line comments with //. The multiline comments are preserved in the CSS output where possible, while the single-line comments are removed.

See here for the docs.

like image 23
CJ- Avatar answered Nov 15 '22 05:11

CJ-