Vue with css modules
See original GitHub issueI’m able to run storybook in my Vue project however the css modules are missing. I’ve also created a new storybook project with the default webpack config and I have the same issue. No styles
i have a component like this
<template>
<div :class="$style.component">
red text
</div>
</template>
<script>
export default {
name: 'Thing'
}
</script>
<style module>
.component {
color: red;
}
</style>
and the rendered html is
<div>
red text
</div>
With no css class. Do I need to do something specific to enable css modules?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:6 (2 by maintainers)
Top Results From Across the Web
CSS Modules - Vue Loader
CSS Modules is a popular system for modularizing and composing CSS. vue-loader provides first-class integration with CSS Modules as an alternative for ...
Read more >CSS Modules in Vue.js - Professional Web Development
In these types of frameworks, it has become popular to use CSS Modules. It is a way of automatically creating unique class names,...
Read more >CSS Modules: How do they work in Vue? - Mattermost
A CSS Module is a file that, by default, scopes all of your class names and animations locally. It enables you to build...
Read more >Vue.js - Scoped Styles vs CSS Modules - Netguru
CSS Modules gained their popularity due to the React community that quickly adopted this technology. Vue.js takes it to another level by ...
Read more >Vue 3 provided an in-build CSS-module feature without ...
Using CSS modules in Vue. Step 1: Write a CSS inside the style of the component like below. Inside the style tag should...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@chrisjbrown Yeah, you need to configure a webpack rule for
.css
file in the way Vue Loader Docs describing (if you have files something like SASS, add rules for them too.) I’m not surevue-cli-plugin
handles it or not, though.Sample Config
CodeSandbox
I recently face this problem and unfortunately none of the suggestion above worked for me as is. The idea is correct, but I had to copy the vue-cli actual webpack config implementation for the css rule to make this work instead of using the one shown by pocka or other users above. For people who face the same problem, this is what works for me:
Run
vue-cli-service inspect > output.js
this will print out the webpack config vue actually uses. Refer to this official guide. Doing this will make sure the rules used by storybook is the one used by vue itself.Look for the css rule from the file and copy pasted the whole css rule to storybook webpack config
module.rule
. At the time of this post, this is what the complete css rule look like<style module>
will work just fine.NOTE: as the goal is to replace the css rule the storybook uses, make sure if you extend the existing rules, you exclude the original css rule! The code @pocka shown here helped do the job: