postcss / postcss-custom-properties

Use Custom Properties in CSS
https://postcss.github.io/postcss-custom-properties
MIT License
597 stars 77 forks source link

preserve: false dosen't work #138

Closed pldg closed 5 years ago

pldg commented 5 years ago

CSS variable are preserved even if preserve: false. This happen only for variables imported from another folder. A minimal test repository (with two temporary solutions): test-postcss-custom-properties

jonathantneal commented 5 years ago

The issue is that you are transforming the file without access to the variable, so it’s like you never imported another file at all. Unresolved custom properties are always preserved.

pldg commented 5 years ago

I'm not sure I understand.

I've two variables in style.css

Both variables are used inside body selector. For what I understand preserve: false should transform both variables to their original value but as you can see in the bundle dist/main.css only --text-color is transformed to red.

Why --bg-color is not transformed to lightblue?

Why using postcss-import solve the problem?

jonathantneal commented 5 years ago

--bg-color is imported from another file inside another folder: partials/var.css.

It is never imported at the time postcss runs. I don’t know why. That is why the property using var() is neither transformed or removed.

pldg commented 5 years ago

It's strange. Do you think it's a postcss-loader's bug?

jonathantneal commented 5 years ago

Yes, or some kind of Webpack plugin ordering issue.