MadLittleMods / postcss-css-variables

PostCSS plugin to transform CSS Custom Properties(CSS variables) syntax into a static representation
https://madlittlemods.github.io/postcss-css-variables/playground/
Other
536 stars 62 forks source link

postcss-css-variables: variable --color-text-5 is undefined and used without a fallback #133

Closed cjy816618 closed 1 year ago

cjy816618 commented 1 year ago

"postcss-css-variables": "^0.17.0",

Input:

:root {
  --color-text-5: red;
}
div {
  color: var(--color-text-5);
}

Output:

div {
  color: undefined;
}

Expected output:

div {
  color: red;
}
MadLittleMods commented 1 year ago

@cjy816618 Please provide your CSS input, what this plugin outputs, and what you expected the output to look like

Input:

...

Output:

...

Expected output:

...
cjy816618 commented 1 year ago

css: image plgin: image package: image output: image I hope to be compatible with ie, I used this plugin, but it doesn't work in ie11

MadLittleMods commented 1 year ago

@cjy816618 Please update the issue description with a copy-pastable text version of a minimal reproduction case; input, output, expected output.

Ideally reproducible in the code playground: https://madlittlemods.github.io/postcss-css-variables/playground/

cjy816618 commented 1 year ago

input:

:root{
  --color-text-5: red;
}
div{
  color: var(--color-text-5);
}

output:

div{
  color: undefined;
}

expected output:

div{
  color: red;
}
MadLittleMods commented 1 year ago

I can't reproduce in the code playground,

Input:

:root {
  --color-text-5: red;
}
div {
  color: var(--color-text-5);
}

Output looks as your expected result:

div {
  color: red;
}
cjy816618 commented 1 year ago

Is it caused by scss? I wrote it through scss

MadLittleMods commented 1 year ago

It sounds like you haven't isolated the problem. You need to get the exact input going into the postcss-css-variables plugin. Comment out the postcss-css-variables plugin and all plugins after it (leave the plugins before), make a build and show the output (text form please).

cjy816618 commented 1 year ago

This problem has been solved, and this method can be usedimage