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

[CSS Modules] Module/Filename not included in scoped class names #261

Open
8 of 9 tasks
tobi-fis opened this issue Sep 26, 2023 · 1 comment
Open
8 of 9 tasks

[CSS Modules] Module/Filename not included in scoped class names #261

tobi-fis opened this issue Sep 26, 2023 · 1 comment
Labels
invalid This doesn't seem right

Comments

@tobi-fis
Copy link

Related plugins

Describe the bug

Hey everyone,
When using the built-in CSS Modules feature of vue with vite, the generated class names of SFCs do not behave as expected.

Expected
Coming from vue+webpack, the out-of-the-box behavior was aligned with the way CSS modules are supposed to function. Generated class names should normally look like this by default:
[moduleName]_[className]_[hash]

e.g. for class mainButton in the <style module> section of pageHeader.vue
pageHeader_mainButton__active_h6fhX

Actual
But for some reason, the moduleName part is ommited when using vite, making classes look like this:
_[className]_[hash]
e.g.
_mainButton__active_h6fhX

While classes are still technically scoped through the hash value, this should not be the default behavior when using CSS Modules.
Why is this different now in vite?

What I have tried
Of course I have tried to configure the css.module.generateScopedName option of the vite.config.ts to recreate the default behavior as described in the docs:
generateScopedName: "[name]__[local]___[hash:base64:5]"

But the "name" part then renders to this abomination:
App-vue-vue-type-style-index-0-lang-module
insted of just App

I have tried other configurations found on stackoverflow etc. but I have yet to find a working solution.

Thanks for any help.

PS: I tried it with a discussion first, but saw that they are alle staying unanswered for months. Sorry if this is wrong.

Reproduction

https://stackblitz.com/edit/vue3-vite-starter-kf4t5f?file=src%2FApp.vue

Steps to reproduce

Open the stackblitz demo, let it render and inspect the tag's generated class names.

System Info

System:
    OS: Windows 10 10.0.19045
    CPU: (16) x64 12th Gen Intel(R) Core(TM) i7-1260P        
    Memory: 15.63 GB / 31.70 GB
  Binaries:
    Node: 18.16.1 - C:\Program Files\nodejs\node.EXE
    npm: 9.8.1 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.19041.1266.0), Chromium (117.0.2045.43)
    Internet Explorer: 11.0.19041.1566
  npmPackages:
    @vitejs/plugin-vue: 4.2.3 => 4.2.3 
    vite: 4.4.3 => 4.4.3

Used Package Manager

npm

Logs

No response

Validations

@edison1105 edison1105 added invalid This doesn't seem right and removed pending triage labels Sep 24, 2024
@edison1105
Copy link
Member

It's related to vite, you should create a new issue in https://github.com/vitejs/vite

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants