-
-
Notifications
You must be signed in to change notification settings - Fork 109
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
CSS @import does not work with absolute paths (node_modules
)
#614
Comments
node_modules
& aliases) or relative paths pointed outside public directory
import "./style.module.css" doesn't work either. Could not load ./node_modules/my-gui-toolkit/styles.module.css (imported by npm/my-gui-toolkit@1.0.0/index.js): local access not allowed |
@makoven Is that something in |
@rschristian It's illegal to import css file in js too :) But this does not stop anyone. There is no other way to distribute a components library with real CSS modules other than to leave them in their original form. So why not? |
@makoven It's acceptable to use CSS imports for web apps, yes, as you know the environment in which it will be used. You can't distribute a module knowing where it's used, however, so that is not something you can do. The error is correct here. The correct way to distribute a component built with CSS modules is to replaces usages with generated hashes for the class names. Replacing in the component and in the CSS file means you can consume as if it's any other CSS, while ensuring no collisions due to the hashes. Take a look at microbundle if you'd like an example of a tool that'll handle this. |
@rschristian thanks for pointing out the microbundle |
FYI: The aliasing or importing modules outside the public directory feature has landed in |
node_modules
& aliases) or relative paths pointed outside public directorynode_modules
)
Importing CSS from |
Edit: Problem was more widespread than I thought.
Describe the bug
CSS
@import
syntax only works with relative paths within the public directory. Anything else is a no-go. For example:node_modules
src
(alias)@import
are all things that you cannot do with WMR.
To Reproduce
Created a simple repo that shows off with the src alias: https://github.com/rschristian/wmr-css-import-syntax-paths
Obviously other methods fail too, though they fail for the same reason.
Expected behavior
@import
syntax is supported fully. The biggest problem is withnode_modules
using it breaking, as that's mostly out of the control of the user. They'd need to slip in with a post-install script and cut that out else WMR will have issues.Desktop (please complete the following information):
The text was updated successfully, but these errors were encountered: