Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/benmerckx/lightningcss-plugins
https://github.com/benmerckx/lightningcss-plugins
Last synced: 8 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/benmerckx/lightningcss-plugins
- Owner: benmerckx
- Created: 2023-09-21T07:26:06.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-09-22T07:35:23.000Z (over 1 year ago)
- Last Synced: 2024-10-31T12:14:40.296Z (about 2 months ago)
- Language: TypeScript
- Size: 15.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# lightningcss-plugins
## pxToRem
Convert pixel values to rem values.
```ts
import {code} from 'lightningcss'
import {pxToRem} from 'lightningcss-plugins'interface PxToRemOptions {
/** Represents the root element font size (default: 16) */
rootValue?: number
/** The decimal numbers to allow the REM units to grow to (default: 5) */
unitPrecision?: number
/** Set the minimum pixel value to replace (default: 0) */
minPixelValue?: number
}const {code} = transform({
visitor: pxToRem(/* options */),
filename: 'test.css',
code: Buffer.from(`
body {
font-size: 16px;
max-width: 960px;
}
`)
})
```Result:
```css
body {font-size: 1rem; max-width: 60rem}
```## suffixes
Append nested type selectors to the parent selector like is the case in scss/less.
As long as the outer selector ends with an alphanumeric name (like class, ID,
and element selectors), you can use the parent selector to append additional text.```ts
import {code} from 'lightningcss'
import {suffixes} from 'lightningcss-plugins'const {code} = transform({
visitor: suffixes,
filename: 'test.css',
code: Buffer.from(`
.accordion {
max-width: 600px;&__copy {
display: none;
color: gray;&--open {
display: block;
}
}
}
`)
})
```Result:
```css
.accordion {max-width: 600px}
.accordion__copy {display: none; color: gray}
.accordion__copy--open {display: block}
```Note: this means it is no longer possible to use nesting to specify the element:
```css
.class {&div {color: red}}
/* Will transform to: */
.classdiv {color: red}
/* But you can use is: */
.class {&:is(div) {color: red}}
/* Which will yield: */
.class:is(div) {color: red}
```