upload project source code
This commit is contained in:
20
前端源码/uni-app/postcss-rpx-to-vw.js
Normal file
20
前端源码/uni-app/postcss-rpx-to-vw.js
Normal file
@@ -0,0 +1,20 @@
|
||||
// PostCSS 插件:将 rpx 单位转换为 vw
|
||||
// 基于 750px 设计稿,1rpx = 100vw / 750 = 0.1333vw
|
||||
|
||||
const postcssRpxToVw = () => {
|
||||
return {
|
||||
postcssPlugin: 'postcss-rpx-to-vw',
|
||||
Declaration(decl) {
|
||||
if (decl.value.includes('rpx')) {
|
||||
decl.value = decl.value.replace(/(\d+(?:\.\d+)?)rpx/g, (match, num) => {
|
||||
const vw = (parseFloat(num) / 750 * 100).toFixed(4);
|
||||
return `${vw}vw`;
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
postcssRpxToVw.postcss = true;
|
||||
|
||||
export default postcssRpxToVw;
|
||||
Reference in New Issue
Block a user