-
-
Notifications
You must be signed in to change notification settings - Fork 86
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
minification does not happen for gradients #306
Comments
This does not only happen on gradients. Any style with Parentheses like You can see this in test case, the parser ignores anything between parentheses Lines 19 to 27 in b8c0878
You can workaround this by providing your own middleware. import { compile, middleware, serialize, stringify } from 'stylis'
const parenthesesStartRegex = /\(\s+/g;
const parenthesesEndRegex = /\s+\)/g;
const commaSpaces = /,\s+/g;
const parenthesesRegex=/^[a-z-]+\(\s+/ig;
const minifyParentheses = element => {
if (
element.type === 'decl' &&
typeof element.props === 'string' &&
typeof element.children === 'string' &&
parenthesesRegex.test(element.children)
) {
element.return = `${element.props}:${element.children
.replaceAll(parenthesesStartRegex, '(')
.replaceAll(parenthesesEndRegex, ')')
.replaceAll(commaSpaces, ',')};`;
}
};
const css = `
.foo {
background: repeating-linear-gradient(
-45deg,
red,
red 5px,
blue 5px,
blue 10px
);
color: green;
}
.bar {
color: blue;
background: orange;
}
.baz {
background-image:radial-gradient(
ellipse 50rem 50rem,
#8e91e6 0%,
#403f5a 25%,
transparent 46%
)
}
`;
const processedCss = serialize(compile(css), middleware([minifyParentheses, stringify]));
console.log(processedCss) output: .foo{background:repeating-linear-gradient(-45deg,red,red 5px,blue 5px,blue 10px);color:green;}.bar{color:blue;background:orange;}.baz{background-image:radial-gradient(ellipse 50rem 50rem,#8e91e6 0%,#403f5a 25%,transparent 46%);} CaveatsNote that this example doesn't consider nested |
Versions
[email protected]
Problem
Stylis does minification and it works great:
The problem happens with
radial-gradient
&repeating-linear-gradient
:👆 notice that
.foo
&.baz
are not minified.Reproduction
https://codesandbox.io/s/awesome-rgb-wf0j3e
The text was updated successfully, but these errors were encountered: