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

[FIX] Extract class names with hyphens #6

Merged
merged 2 commits into from Apr 3, 2024

Conversation

zyishai
Copy link
Contributor

@zyishai zyishai commented Apr 3, 2024

This PR fixes #5.

Solution description

When Vite compiles CSS modules, it creates a JS module and exports the classnames both as named exports and also in a default export object:

export const title = "_title_drylp_12";
export const small = "_small_drylp_17";
export const medium = "_medium_drylp_20";
export const large = "_large_drylp_23";
export default {
        title: title,
        small: small,
        medium: medium,
        large: large
};

However, when the classname contains an hyphen, it'll be exposed only in the default export object:

export const success = "_success_h5dzl_10";
export const error = "_error_h5dzl_13";
export default {
        "basic-button": "_basic-button_h5dzl_6",
        success: success,
        error: error
};

The fix was to extract the classname strings from both types of exports.

@sultan99
Copy link
Owner

sultan99 commented Apr 3, 2024

Good job!
Thank you @zyishai!

@sultan99 sultan99 merged commit 2ae5d78 into sultan99:main Apr 3, 2024
@zyishai
Copy link
Contributor Author

zyishai commented Apr 3, 2024

👍 I tested it in a local project on my machine and it worked beautifully. According to the CSS Specification, an identifier (including class names) can contain only alphanumeric letters, hyphen and underscore, so I'm pretty sure those Regexes cover every valid class name.

If there are more things to work on for the next release, please let me know. I really like Stylin and would be happy to contribute more.

@sultan99
Copy link
Owner

sultan99 commented Apr 3, 2024

Thank you @zyishai!
I have tested it and everything looks good to go.
I have published a new release which you can find at https://github.com/sultan99/stylin/releases/tag/v0.5.0.

@zyishai
Copy link
Contributor Author

zyishai commented Apr 3, 2024

@sultan99 It was a great pleasure working on the Vite plugin!
Of course, I'll continue to support it and this project (already thinking of supporting raw css files, we'll see how it goes 😁).
Thanks for being quick to respond and to act. I'm off to explore and experiment @holycow 😉

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

Successfully merging this pull request may close these issues.

Kebab case CSS class names not functioning in vite plugin
2 participants