Skip to content
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

Compatible with CSS minimizing caused by Taro build command #22

Merged
merged 4 commits into from
Jun 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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