cssnano / cssnano

A modular minifier, built on top of the PostCSS ecosystem.

Home Page:https://cssnano.github.io/cssnano/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Wrong minification on invalid input

felixmosh opened this issue · comments

Hi,

I have custom strings inside my css,

body { border: "unit(--borderWidth, px)" solid "color(color-1)"; }

CSS-Nano removes the strings after minification, and it becomes

body{border:solid}

I`ve tried, and if the input is only:

body { border-width: "unit(--borderWidth, px)"; }

The output will remain that string.

body{border-width:"unit(--borderWidth, px)"}

Expected result, those css strings should remain at the minified result.

Sorry, we expect you to feed valid CSS to cssnano. Minification should be done as the final step in your CSS pipeline.

Yeah, but why it remove the string? if it not familiar with that it suppose to keep it...

Because the code makes executive decisions based on known keywords and CSS structure in order to optimise the values. You can disable this behaviour by disabling orderedValues.

It's hard to determine what the code is supposed to do given that the input is invalid, and attempts to handle it would be somewhat ambiguous (e.g. should the first value be a width, style, or a colour?). If you believe that it should be handled differently from how it works currently, you're welcome to state your case, and if possible, submit a PR.

Can you point the place of the minification logic?

@andyjansson, PR is ready, WDYT?

Seeing as we've landed on not changing the current behaviour (#403), I'm closing this issue.

@felixmosh Thank you for contributing to the project. Even though your contribution ended up being rejected, your involvement is very much appreciated. Unfortunately, sometimes we have to reject PRs in order to keep a certain level of maintainability. I hope this doesn't discourage you from contributing in the future.