Skip to content

Commit

Permalink
feat: support mako px2rem
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaohuoni committed Aug 2, 2024
1 parent 6dc3176 commit 6ecee41
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion packages/plugins/src/hd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,33 @@ export default (api: AlitaApi) => {
...(configPx2rem || {}),
};
draftConfig.mako = mako;
const hasMagicChars = (pattern: string) => {
return (
pattern.includes('*') ||
pattern.includes('\\') ||
pattern.includes('(') ||
pattern.includes(')') ||
pattern.includes('^') ||
pattern.includes('$')
);
};
draftConfig.mako.px2rem = {
...px2remConfig,
// 将正则转成字符串
selectorDoubleList: px2remConfig.selectorDoubleRemList.map(
(i: string) => `${i}`.replaceAll('/', ''),
(i: string) => {
if (!i.includes('/')) return i;
const reStr = `${i}`.replaceAll('/', '');
if (hasMagicChars(reStr)) {
return reStr;
}
// FIXME: 更新 mako 的时候,需要修改这里,如果那边有修改配置,则要做出对应变动
// https://github.com/umijs/mako/blob/246ffd3440ec2705a1277c64fc0f554d68f0fe83/crates/mako/src/visitors/css_px2rem.rs#L152
return `(${reStr})`;
},
),
};
delete draftConfig.mako.px2rem.selectorDoubleRemList;
}

return draftConfig;
Expand Down

0 comments on commit 6ecee41

Please sign in to comment.