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
540 stars 62 forks source link

Define global variables as css file #60

Open artem-popov opened 7 years ago

artem-popov commented 7 years ago

It's just a suggestion for implement.

Now global variables defined as 'variables' in options. And it is an js object.

For me it would be better to import variables as file instead, for example:

options: { variablesPath: 'src/variables.css' }

P.S. Why I need it:

It's because I use css-modules and have no way to set variables declarations somewhere top.

It is possible to import variables from every file which needs them, but I'm using variables as a method to decouple components from global files :) As a context for component...

The solution I use for now is implicitly importing of variables file in sass-loader.

nathanchase commented 6 years ago

Yes! This is what I've been trying to do - just reference a "global_variables.css" file that has my variables, custom-media, mixins, etc. and have webpack/postcss deliver them to all my app pages/components without me having to explicitly @import that file into every other CSS file in my app.

cheshrkat commented 6 years ago

This would be great. We have a project structure with separate CSS files for each component, and currently we have to duplicate the shared CSS custom props in every CSS file to enable IE11. The bloat really adds up.

mbulfair commented 5 years ago

This is still an issue, and given I have css modules, this prevents me from using this plugin, the custom-properties plugin has a importFrom option that works exactly like I need but doesn't do the local variables. Can't win.

MadLittleMods commented 5 years ago

@mbulfair Pull request welcome

rajatbarman commented 5 years ago

Need this functionality for people using css-modules

damianfrizzi commented 5 years ago

@MadLittleMods I really need this and would like to start working on a PR. Could you give me some hints on how you would approach this problem?

MadLittleMods commented 5 years ago

@damianfrizzi Some rough overview,

DevinCarl commented 3 years ago

any update about this implement?

nilsgabriel commented 2 years ago

Is there any other solution to solve this?

nathanchase commented 2 years ago

My solution has been to just point to a css file and not use this plugin anymore. Unless you have IE as a requirement, custom properties are fully supported now. https://caniuse.com/css-variables

// variables.css
:root {
   --blackColor: hsl(0, 0%, 0%);
}