diff --git a/package.json b/package.json index 693af59..1589169 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@dcasia/mini-program-tailwind-webpack-plugin", - "version": "1.4.1", + "version": "1.4.2", "description": "让你的小程序用上原汁原味的 Tailwind/Windi CSS", "keywords": [ "mini-program", diff --git a/src/postcss/index.ts b/src/postcss/index.ts index eb13aca..a19391a 100644 --- a/src/postcss/index.ts +++ b/src/postcss/index.ts @@ -15,8 +15,8 @@ export function transformSelector(options: Options) { * Note that in mini program environment ':not()' selector can only be used when it's combined with other selectors * e.g. view:not() works but the standalone :not() selector couldn't work */ - customReplacement.set(/^(\.-?space-\w)(-.+?)\s.*/, spaceBetweenItems.map(item => `$1$2:not($1-reverse) > ${ item }:not([hidden]):not(:first-child), $1$2$1-reverse > ${ item }:not([hidden]):not(:last-child)`).join(', ')) - customReplacement.set(/^(\.-?space-\w-reverse).*/, spaceBetweenItems.map(item => `$1 > ${ item }:not([hidden])`).join(', ')) + customReplacement.set(/^(\.-?space-\w)(-.+?)\s?>.*/, spaceBetweenItems.map(item => `$1$2:not($1-reverse)>${ item }:not([hidden]):not(:first-child), $1$2$1-reverse>${ item }:not([hidden]):not(:last-child)`).join(', ')) + customReplacement.set(/^(\.-?space-\w-reverse).*/, spaceBetweenItems.map(item => `$1>${ item }:not([hidden])`).join(', ')) return { postcssPlugin: 'transformSelectorName', @@ -85,7 +85,14 @@ const valueConvertor = { function transformAllValue(raw: string, targets: number[], unit: SourceUnit, options: Options) { for (const value of targets) { - raw = raw.replace(value + unit, valueConvertor[ unit ](value, options.designWidth) + TargerUnit.RPX) + + /** + * Handle cases like '.5rem' '-.5rem' etc + */ + const pattern = new RegExp((value + unit).replace(/^(-?)0(\.)/, '$10?$2').replace(/\./, '\\.')) + + raw = raw.replace(pattern, valueConvertor[ unit ](value, options.designWidth) + TargerUnit.RPX) + } return raw