Skip to content

Commit e109073

Browse files
authored
Merge pull request #22 from dcasia/fix-space-between
Compatible with CSS minimizing caused by Taro build command
2 parents 2ac5b30 + d35aa7a commit e109073

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@dcasia/mini-program-tailwind-webpack-plugin",
3-
"version": "1.4.1",
3+
"version": "1.4.2",
44
"description": "让你的小程序用上原汁原味的 Tailwind/Windi CSS",
55
"keywords": [
66
"mini-program",

src/postcss/index.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ export function transformSelector(options: Options) {
1515
* Note that in mini program environment ':not()' selector can only be used when it's combined with other selectors
1616
* e.g. view:not() works but the standalone :not() selector couldn't work
1717
*/
18-
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(', '))
19-
customReplacement.set(/^(\.-?space-\w-reverse).*/, spaceBetweenItems.map(item => `$1 > ${ item }:not([hidden])`).join(', '))
18+
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(', '))
19+
customReplacement.set(/^(\.-?space-\w-reverse).*/, spaceBetweenItems.map(item => `$1>${ item }:not([hidden])`).join(', '))
2020

2121
return {
2222
postcssPlugin: 'transformSelectorName',
@@ -85,7 +85,14 @@ const valueConvertor = {
8585
function transformAllValue(raw: string, targets: number[], unit: SourceUnit, options: Options) {
8686

8787
for (const value of targets) {
88-
raw = raw.replace(value + unit, valueConvertor[ unit ](value, options.designWidth) + TargerUnit.RPX)
88+
89+
/**
90+
* Handle cases like '.5rem' '-.5rem' etc
91+
*/
92+
const pattern = new RegExp((value + unit).replace(/^(-?)0(\.)/, '$10?$2').replace(/\./, '\\.'))
93+
94+
raw = raw.replace(pattern, valueConvertor[ unit ](value, options.designWidth) + TargerUnit.RPX)
95+
8996
}
9097

9198
return raw

0 commit comments

Comments
 (0)