Skip to content
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

Alias another CSS module file to avoid repeating (long) filepaths #753

Open
evertheylen opened this issue Jun 4, 2024 · 2 comments
Open

Comments

@evertheylen
Copy link

evertheylen commented Jun 4, 2024

The support for scoping CSS variables is great and exactly what I'd expect from CSS modules.

However, consider a CSS module that defines some theme colors:

:root {
  --primary: darkblue;
  --background: white;
}

Using the above module can get rather verbose when the directory structure of your project grows. For example, I can see this happening:

.foobar {
  color: var(--primary from '../../../../style/theme/colors.module.css');
  background-color: var(--background from '../../../../style/theme/colors.module.css');
}

I think it would be nice to have a syntax to alias another CSS module file, something like this:

@alias '../../../../style/theme/colors.module.css' as colors;

.foobar {
  color: var(--primary from colors);
  background-color: var(--background from colors);
}

The syntax above is just an idea, I just don't want to repeat potentially long filepaths.

(I've searched for ways in which this might already be implemented, but couldn't find anything. Let me know if I'm wrong!)

@jeffijoe
Copy link

If you're using Vite you could use an alias like @/colors.module.css but I would also second this feature request. 🙏

@evertheylen
Copy link
Author

evertheylen commented Jun 27, 2024

Actually, I found out that postcss-modules-values supports this usecase through @value.

The lightningcss website states that it doesn't support "the @value rule – superseded by standard CSS variables.". I personally see two usecases why it useful and not superseded by standard CSS variables:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants