class2css
v1.1.28
Published
class2css is a plugin for Vite that converts CSS classes into meaningful CSS styles, simplifying the process of working with CSS in JavaScript applications. This plugin supports HMR (Hot Module Replacement) during development, enhancing performance and de
Downloads
128
Maintainers
Readme
class2css
class2css
is a plugin for Vite that converts CSS classes into meaningful CSS styles, simplifying the process of working with CSS in JavaScript applications. This plugin supports HMR (Hot Module Replacement) during development, enhancing performance and development experience.
Installation
You can install class2css
via npm:
npm install class2css
Configuration
To configure class2css with Vite, add it to your Vite configuration file (vite.config.js):
import { defineConfig } from 'vite';
import class2css from 'class2css';
export default defineConfig({
plugins: [class2css()]
});
Usage
In all templates in your .vue files, you can use the following keywords as class names to generate the corresponding CSS styles. Here is a list of supported keywords: Dưới đây là danh sách các key:
| Key | Property | Example | | ------ |---------------------------------|------------------------------------------------------| | c | color | c-red -> color: red; | | bg | background-color | bg-blue -> background-color: blue; | | fs | font-size | fs-14 -> font-size: 14px; | | fw | font-weight | fw-bold -> font-weight: bold; | | w | width | w-100 -> width: 100px; | | h | height | h-200 -> height: 200px; | | m | margin | m-10 -> margin: 10px; | | p | padding | p-20 -> padding: 20px; | | bd | border | bd-1px-solid-black -> border: 1px solid black; | | br | border-radius | br-5 -> border-radius: 5px; | | ws | white-space | ws-nowrap -> white-space: nowrap; | | ov | overflow | ov-x-hidden -> overflow-x: hidden; | | z | z-index | z-10 -> z-index: 10; | | block | display | block -> display: block; | | inline | display | inline -> display: inline; | | inline_block | display | inline_block -> display: inline-block; | | none | display | none -> display: none; | | i | font-style | i -> font-style: italic; | | u | text-decoration | u -> text-decoration: underline; | | lt | text-decoration | lt -> text-decoration: line-through; | | o | text-decoration | o -> text-decoration: overline; | | fn | font-style | fn -> font-style: normal; | | tn | text-decoration | tn -> text-decoration: none; | | tb | font-weight | tb -> font-weight: bold; | | upp | text-transform | upp -> text-transform: uppercase; | | low | text-transform | low -> text-transform: lowercase; | | cap | text-transform | cap -> text-transform: capitalize; | | usn | user-select | usn -> user-select: none; | | usa | user-select | usa -> user-select: auto; | | row | layout (flex-direction: row) | row -> flex-direction: row; | | col | layout (flex-direction: column) | col -> flex-direction: column; | | static | position | static -> position: static; | | relative | position | relative -> position: relative; | | fixed | position | fixed -> position: fixed; | | absolute | position | absolute -> position: absolute; | | sticky | position | sticky -> position: sticky; | | t | edgePosition (top) | t-0 -> top: 0; | | r | edgePosition (right) | r-0 -> right: 0; | | b | edgePosition (bottom) | b-0 -> bottom: 0; | | l | edgePosition (left) | l-0 -> left: 0; | | vt | vertical-align | vt -> vertical-align: top; | | vm | vertical-align | vm -> vertical-align: middle; | | vb | vertical-align | vb -> vertical-align: bottom; | | tl | text-align | tl -> text-align: left; | | tc | text-align | tc -> text-align: center; | | tr | text-align | tr -> text-align: right; | | tj | text-align | tj -> text-align: justify; | | rl | align (left) | rl -> align: left; | | rc | align (center) | rc -> align: center; | | rr | align (right) | rr -> align: right; | | rt | align (top) | rt -> align: top; | | rm | align (middle) | rm -> align: middle; | | rb | align (bottom) | rb -> align: bottom; | | rw | align (space-between) | rw -> align: space-between; | | ra | align (space-around) | ra -> align: space-around; | | re | align (space-evenly) | re -> align: space-evenly; | | cl | align (left) | cl -> align: left; | | cc | align (center) | cc -> align: center; | | cr | align (right) | cr -> align: right; | | ct | align (top) | ct -> align: top; | | cm | align (middle) | cm -> align: middle; | | cb | align (bottom) | cb -> align: bottom; | | cw | align (space-between) | cw -> align: space-between; | | ca | align (space-around) | ca -> align: space-around; | | ce | align (space-evenly) | ce -> align: space-evenly; | | sd | box-shadow | sd-2px-2px-5px-gray -> box-shadow: 2px 2px 5px gray; | | cur | cursor | cur-pointer -> cursor: pointer; | | op | opacity | op-50 -> opacity: 0.5; | | to | text-overflow | to-ellipsis -> text-overflow: ellipsis; |
Here’s a basic example of how to use class2css in your .vue files:
<template>
<div class="cap i c-red bg-blue">abc</div>
</template>
<script>
export default {
name: 'ExampleComponent'
}
</script>
<style>
</style>
Automatically generate CSS as shown below. This helps us save a lot of time.
<template>
<div class="cap i c-red bg-blue">abc</div>
</template>
<script>
export default {
name: 'ExampleComponent'
}
</script>
<style>
/* The generated CSS will be: */
.cap {
text-transform: uppercase;
}
.i {
font-style: italic;
}
.c-red {
color: red;
}
.bg-blue {
background-color: blue;
}
</style>