-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7a2488d
commit 5fcc40b
Showing
3 changed files
with
15 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
const postcss = require('postcss') | ||
|
||
module.exports = postcss.plugin('wx-px2rpx', (opts = {}) => { | ||
const { proportion = 1 } = opts | ||
|
||
const pxRegExp = /\b(\d+(\.\d+)?)px\b/ | ||
|
||
const {proportion = 1} = opts | ||
const pxRegExp = /\b(\d+(\.\d+)?)px\b/g | ||
return (root) => { | ||
root.replaceValues(pxRegExp, { fast: 'px' }, string => `${(proportion * Number(string.replace(/px$/, '')))}rpx`); | ||
root.replaceValues(pxRegExp, {fast: 'px'}, string => { | ||
return `${proportion * parseInt(string)}rpx` | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
chengpan168
via email
Author
Owner
|
||
}) | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
使用parseInt, 觉得要考虑下浮点数的情况