css / csso

CSS minifier with structural optimizations
https://css.github.io/csso/csso.html
MIT License
3.76k stars 188 forks source link

Allowing exclamation comments inside classes #327

Closed ariel-hive closed 7 years ago

ariel-hive commented 7 years ago

CSSRTL (http://rtlcss.com/) requires /! comments inside the classes and even inline within the css codes in order for it to fully work, for example: `font-family: "Droid Sans", sans-serif /rtl:prepend:"Droid Arabic Kufi",*/; `

However from what I've played around with CSSO (csso-loader for webpack), it will remove all comments inside a class, even the ones marked as /*! (i've even tried comments="exclamation"

lahmatiy commented 7 years ago

CSSO should be last one in CSS processing pipeline. So use csso-loader as last loader, or just before CSSRTL.

ariel-hive commented 7 years ago

Hey Iahmatiy, Thanks for the reply!

I have it as far as I can to the end (can't go after sass or it will break everything): { test: /.scss$/, exclude: /(node_modules|bower_components)/, loader: ExtractTextPlugin.extract( 'style-loader', 'css-loader!postcss-loader!csso-loader!sass ) },

CSSRTL is used later on top of the generated css. I did try some debuging and looking at the output from this and CSSO will only keep the /*! if it encapsulates the entire class - otherwise it will be removed

lahmatiy commented 7 years ago

Thank you for clarification. Well, you need use csso (or any other minifier) after rtlcss anyway. All minifiers removes comments and it's quite complicate to keep them since CSS is restructing during minification. If you use rtlcss as a PostCSS plugin, then you can use postcss-csso. I think there should be an instruction somewhere how to use rtlcss with CSS minifiers. @ai, could you help?

ai commented 7 years ago

@ariel-hive I think main problem in this case is that you run CSS minificator before RTLCSS. All tools was created in thoughts to run CSS minifcator as last step.

@lahmatiy but, I think exclamation comments support is good thing. There is a cases, when comment should be left in minificated version. For example, legacy notes.

lahmatiy commented 7 years ago

@ai Issue is about keeping comments inside rules anchored to a declaration or related things. As you know it's too hard keep those comments while minifying. Btw exclamation comments are supported by csso on top level but not inside rules or at-rules, specially for legacy notes.

ai commented 7 years ago

I am agree that in this case we find a way how to run RTLCSS before csso :)

Btw exclamation comments are supported by csso on top level but not inside rules or at-rules, specially for legacy notes.

Great! It is exactly what I mean.

lahmatiy commented 7 years ago

Closing since issue doesn't related to CSSO itself, but the general problem using RTLCSS with CSS minifiers.