vite-plugin-antd-style-px-to-rem
Version:
A Vite plugin that automatically converts px values to rem units in antd-style CSS template literals, createStyles functions, and JSX attributes during build time
70 lines (65 loc) • 1.72 kB
TypeScript
import { Plugin } from 'vite';
interface AntdStylePxToRemOptions {
/**
* Root value for px to rem conversion
* @default 16
*/
rootValue?: number;
/**
* Decimal precision for rem values
* @default 5
*/
unitPrecision?: number;
/**
* Minimum pixel value to convert
* @default 0
*/
minPixelValue?: number;
/**
* Properties to convert (supports wildcards)
* @default ['*']
*/
propList?: string[];
/**
* Selectors to ignore (for future use)
* @default []
*/
selectorBlackList?: (string | RegExp)[];
/**
* Whether to replace original values or add alongside
* @default true
*/
replace?: boolean;
/**
* Whether to convert px in media queries
* @default false
*/
mediaQuery?: boolean;
/**
* File patterns to include
*/
include?: string | RegExp | (string | RegExp)[];
/**
* File patterns to exclude
*/
exclude?: string | RegExp | (string | RegExp)[];
/**
* CSS template function names to process
* @default ['css']
*/
cssTemplateFunctions?: string[];
/**
* Enable JSX attribute conversion (style, gap, etc.)
* @default true
*/
enableJSXTransform?: boolean;
/**
* Component-property mapping for JSX attribute conversion
* @example { "Flex": ["gap"], "Button": ["size"] }
* @default {}
*/
jsxAttributeMapping?: Record<string, string[]>;
}
declare const defaultOptions: Required<AntdStylePxToRemOptions>;
declare function antdStylePxToRem(options?: AntdStylePxToRemOptions): Plugin;
export { type AntdStylePxToRemOptions, antdStylePxToRem, defaultOptions };