Skip to content

Commit

Permalink
Merge pull request #22 from dcasia/fix-space-between
Browse files Browse the repository at this point in the history
Compatible with CSS minimizing caused by Taro build command
  • Loading branch information
ItsRyanWu authored Jun 16, 2022
2 parents 2ac5b30 + d35aa7a commit e109073
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
13 changes: 10 additions & 3 deletions src/postcss/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e109073

Please sign in to comment.