Skip to content

Commit a9cc607

Browse files
committed
docs: update README files
1 parent 3eca46c commit a9cc607

File tree

2 files changed

+103
-10
lines changed

2 files changed

+103
-10
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ This repository currently includes the following packages:
1212

1313
- **[pxtorem](packages/pxtorem)**: A plugin to convert pixel units to rem units in your CSS.
1414

15-
Each package is located in the [`packages`](packages) directory and follows a consistent structure for ease of development and maintenance.
15+
Each plugin is located in the [`packages`](packages) directory to follow a consistent structure for ease development and maintenance.
1616

1717
## 🤝 Contributing
1818

packages/pxtorem/README.md

Lines changed: 102 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,69 @@
22

33
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.
44

5-
> [!NOTE]
6-
> WIP - This plugin is still a work in progress.
7-
85
## ✨ Features
96

107
- ✅ Converts pixel units to rem units.
118
- ✅ 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.
1311

1412
## ⬇️ Installation
1513

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:
1715

16+
NPM:
1817
```sh
1918
npm install lightningcss-plugin-pxtorem
2019
```
2120

22-
or
23-
21+
PNPM:
2422
```sh
2523
pnpm add lightningcss-plugin-pxtorem
2624
```
2725

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+
2843
## 🚀 Usage
2944

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.
46+
47+
```js
48+
import { transform, composeVisitors } from 'lightningcss';
49+
import pxtorem from 'lightningcss-plugin-pxtorem';
50+
51+
const result = transform({
52+
filename: 'test.css',
53+
minify: true,
54+
code: Buffer.from(`
55+
.foo {
56+
padding: 20px 12px;
57+
}
58+
`),
59+
visitor: composeVisitors([
60+
pxtorem(),
61+
]),
62+
});
63+
64+
console.log(res.code.toString()); // .foo { padding: 1.25rem 0.75rem; }
65+
```
66+
67+
Using `lightningcss-plugin-pxtorem` in your `vite.config.js` file:
3168

3269
```js
3370
import { defineConfig } from "vite";
@@ -44,7 +81,63 @@ export default defineConfig({
4481
});
4582
```
4683

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+
import pxtorem from "lightningcss-plugin-pxtorem";
90+
91+
export default defineConfig({
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/).
48141

49142
## 🤝 Contributing
50143

0 commit comments

Comments
 (0)