cssinjs / jss

JSS is an authoring tool for CSS which uses JavaScript as a host language.
https://cssinjs.org
MIT License
7.08k stars 399 forks source link

feat(jss): Add format option to SheetsRegistry.toString() #1549

Closed briganti closed 3 years ago

briganti commented 3 years ago

What Would You Like to Add/Fix?

This PR adds a new option format to SheetsRegistry.toString so whitespaces are removed from stringified CSS.

jss.createRule('a', {float: 'left', width: '1px'})

// Default
rule.toString()
// outputs:
// .a-id {
//   float: left;
//   width: 1px;
// }

// With format:false
rule.toString({format: false}))
// outputs:
// .a-id{float:left;width:1px;}

Todo

Expectations on Changes

Indentation and line breaks are removed when format: false is passed to SheetsRegistry.toString or rule.toString methods.

Changelog

kof commented 3 years ago

I am not sure regarding "uglify" as an option name, because it may let people think its gonna do more than removing white spaces, but we won't add anything else than whitespace removal because real modification is costly at runtime.

kof commented 3 years ago

How about "removeWhitespace" or "compact" or "format"

kof commented 3 years ago

If "format" it would be true by default.

briganti commented 3 years ago

Thanks for the fast review @kof. I've updated the PR to take into account your feedback.

kof commented 3 years ago

merged, thank you

kof commented 3 years ago

released in https://github.com/cssinjs/jss/releases/tag/v10.8.0