-
-
Notifications
You must be signed in to change notification settings - Fork 104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature]: generate px instead of rem for tailwind classes #437
Comments
there's this postcss lib that converts rem to px but it seems like it is not compatible with twind https://github.com/TheDutchCoder/postcss-rem-to-px |
You can transform the generated CSS using the const config = {
finalize(rule) {
return {
...rule,
// d: the CSS declaration body
// Based on https://github.com/TheDutchCoder/postcss-rem-to-px/blob/main/index.js
d: rule.d.replace(/"[^"]+"|'[^']+'|url\([^)]+\)|(-?\d*\.?\d+)rem/g, (match, p1) => {
if (p1 === undefined) return match
return `${p1 * 16}${p1 == 0 ? '' : unit}`
}),
}
}
}) This could be packaged as preset: export default presetRemToPx({baseValue = 16} = {}) {
return {
finalize(rule) {
return {
...rule,
// d: the CSS declaration body
// Based on https://github.com/TheDutchCoder/postcss-rem-to-px/blob/main/index.js
d: rule.d.replace(/"[^"]+"|'[^']+'|url\([^)]+\)|(-?\d*\.?\d+)rem/g, (match, p1) => {
if (p1 === undefined) return match
return `${p1 * baseValue}${p1 == 0 ? '' : unit}`
}),
}
}
}
} And then: export default defineConfig({
presets: [presetRemToPx()],
}) |
@sastan thank you so much, that worked! |
this worked for me.
|
where does finalize come from? |
Hey! Thanks so much. I get "rule" is undefined when i try to use this. not sure where rule or finalize come from. Thanks! |
Describe the problem
I'm using twind.style to inject tailwind styles into shadow dom for a chrome extension that runs on different sites. The issue is rem is calculated based on the base font size set of
html
element and this varies from site to site. Because of this the default font-size is different on different sites. Is there a way to get CSS output as px instead of rem units? This should make the shadow dom UI consistent across sitesDescribe the proposed solution
ability to get px instead of rem for tailwind classes.
Alternatives considered
No response
Importance
would make my life easier
Additional Information
No response
The text was updated successfully, but these errors were encountered: