vite-plugin-implicit-css-modules
Implicitly replace class names using Vue css modules
Installation
npm install -D vite-plugin-implicit-css-modules
yarn add -D vite-plugin-implicit-css-modules
Usage
plugin config
import vitePluginImplicitCssModules from 'vite-plugin-implicit-css-modules';
export default defineConfig({
plugins: [
{
...vitePluginImplicitCssModules(),
enforce: 'pre',
},
vue(),
],
css: {
modules: {
generateScopedName: '[local]___[hash:base64:5]',
localsConvention: 'camelCase',
},
},
});
Component
With vite-plugin-implicit-css-modules
you can write classes as is:
<template>
<p :class="{ 'red': true }">
Am I red?
</p>
<p class="red bold">
Red and bold
</p>
</template>
<style module>
.red {
color: red;
}
.bold {
font-weight: bold;
}
</style>
and get result:
<p class="red_1VyoJ-uZ">Am I red?</p>
<p class="red_1VyoJ-uZ bold_2dfrX-sE">Red and bold</p>
.red_1VyoJ-uZ {
color: red;
}
.bold_2dfrX-sE {
font-weight: bold;
}
Example
More example
Thanks
Inspired by vue-implicit-css-modules
License
MIT