You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/pxtorem/README.md
+102-9Lines changed: 102 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,32 +2,69 @@
2
2
3
3
The `lightningcss-plugin-pxtorem` plugin is designed to convert pixel units to rem units in your CSS, making it easier to maintain responsive and scalable designs.
4
4
5
-
> [!NOTE]
6
-
> WIP - This plugin is still a work in progress.
7
-
8
5
## ✨ Features
9
6
10
7
- ✅ Converts pixel units to rem units.
11
8
- ✅ Helps maintain responsive and scalable designs.
12
-
- ✅ Customizable options for root value, precision, properties, and more.
9
+
- ✅ Works seamlessly with LightningCSS and Vite ecosystem.
10
+
- ✅ Customizable options.
13
11
14
12
## ⬇️ Installation
15
13
16
-
You can install the `lightningcss-plugin-pxtorem` plugin using npm or yarn:
14
+
You can install the `lightningcss-plugin-pxtorem` plugin using your preferred package manager:
17
15
16
+
NPM:
18
17
```sh
19
18
npm install lightningcss-plugin-pxtorem
20
19
```
21
20
22
-
or
23
-
21
+
PNPM:
24
22
```sh
25
23
pnpm add lightningcss-plugin-pxtorem
26
24
```
27
25
26
+
Yarn:
27
+
```sh
28
+
yarn add lightningcss-plugin-pxtorem
29
+
```
30
+
31
+
Bun:
32
+
```sh
33
+
bun add lightningcss-plugin-pxtorem
34
+
```
35
+
36
+
## ⚙️ Options
37
+
38
+
The plugin accepts the following options:
39
+
40
+
-`rootValue` (default: `16`): The root font size to use for the conversion. This is typically set to `16px`, which is the default font size in most browsers.
41
+
-`unitPrecision` (default: `4`): The number of decimal places to use for the converted values.
42
+
28
43
## 🚀 Usage
29
44
30
-
To use the `lightningcss-plugin-pxtorem` you need to include it in your `vite.config.js` file:
45
+
Using `lightningcss-plugin-pxtorem` plugin in your project.
Using `lightningcss-plugin-pxtorem` in your `vite.config.js` file:
31
68
32
69
```js
33
70
import { defineConfig } from"vite";
@@ -44,7 +81,63 @@ export default defineConfig({
44
81
});
45
82
```
46
83
47
-
This plugin also is compatible with others tools that use Vite.
84
+
With custom options:
85
+
86
+
```js
87
+
import { defineConfig } from"vite";
88
+
import { composeVisitors } from"lightningcss";
89
+
importpxtoremfrom"lightningcss-plugin-pxtorem";
90
+
91
+
exportdefaultdefineConfig({
92
+
css: {
93
+
transformer:"lightningcss",
94
+
lightningcss: {
95
+
visitor:composeVisitors([
96
+
pxtorem({
97
+
rootValue:18,
98
+
unitPrecision:2,
99
+
}),
100
+
]),
101
+
},
102
+
},
103
+
});
104
+
```
105
+
106
+
This plugin is designed to work with [LightningCSS](https://lightningcss.dev/), a CSS processor that provides advanced features and optimizations. It's compatible with the Vite ecosystem like [UI Frameworks](https://patak.dev/vite/ecosystem.html) and [App Frameworks](https://patak.dev/vite/ecosystem.html#app-frameworks), allowing you to use it seamlessly in your projects.
107
+
108
+
## 📜 Example
109
+
110
+
With default options:
111
+
112
+
```css
113
+
/* input.css */
114
+
body {
115
+
font-size: 16px;
116
+
padding: 20px;
117
+
margin: 10px;
118
+
}
119
+
120
+
h1 {
121
+
font-size: 32px;
122
+
line-height: 40px;
123
+
}
124
+
```
125
+
126
+
```css
127
+
/* output.css */
128
+
body {
129
+
font-size: 1rem;
130
+
padding: 1.25rem;
131
+
margin: 0.625rem;
132
+
}
133
+
134
+
h1 {
135
+
font-size: 2rem;
136
+
line-height: 2.5rem;
137
+
}
138
+
```
139
+
140
+
See others examples in the [test folder](./test/).
0 commit comments