Installations
npm install px-rpx-vw-loader
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
14.1.0
NPM Version
6.14.4
Score
67.4
Supply Chain
99.2
Quality
75.7
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Developer
MengFangui
Download Statistics
Total Downloads
1,584
Last Day
1
Last Week
6
Last Month
25
Last Year
274
GitHub Statistics
4 Commits
1 Forks
2 Watching
1 Branches
1 Contributors
Bundle Size
1.11 kB
Minified
593.00 B
Minified + Gzipped
Package Meta Information
Latest Version
1.1.1
Package Id
px-rpx-vw-loader@1.1.1
Unpacked Size
7.67 kB
Size
3.35 kB
File Count
4
NPM Version
6.14.4
Node Version
14.1.0
Total Downloads
Cumulative downloads
Total Downloads
1,584
Last day
-50%
1
Compared to previous day
Last week
-57.1%
6
Compared to previous week
Last month
177.8%
25
Compared to previous month
Last year
-1.1%
274
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
No dependencies detected.
px-rpx-vw-loader
px-rpx-vw-loader将项目中的rpx或者px单位转为vw,实现移动端自适应布局。
rpx的使用方法与微信小程序一样。
使用方法(以vue工程为例)
1// vue.config.js 配置文件 2module.exports = { 3 chainWebpack: (config) => { 4 config.module 5 .rule('rpx') 6 .test(/\.vue$/) 7 .use('px-rpx-vw-loader') 8 .loader('px-rpx-vw-loader') 9 .options({ 10 // 根据设计稿尺寸修改,默认是750(iPhone 6) 11 width: 750, 12 // 转换单位 13 unit: 'rpx', 14 // 转换比例 15 ratio: 1, 16 // 精度 17 unitPrecision: 6 18 }) 19 .end(); 20 } 21}
- width的取值是375到2160的正整数,默认是750,即iPhone 6的设计稿尺寸。
- unit是取值为'rpx' 或者 'px'的字符串,即将文件中的'rpx'或者'px'单位转为vw,默认取值是'rpx'。
- ratio是转换比例,取值是大于0的数值。对于iPhone 6 750的设计稿,页面采用'rpx'相对单位时,ratio设置为1即可。对于iPhone 6 750的设计稿,页面采用'px'单位时(需要根据设计稿标注的尺寸除以2),ratio设置为2即可,当然也可以按照设计稿直接设计稿上标注的像素值,ratio设置为1。
- unitPrecision是转换精度,即保留小数点位数,默认是6位。
说明
vue文件中的template、js和style样式表中的样式单位(rpx或者px),本loader均能实现转换为vw。
class样式支持
- 对象语法
- 数组语法
style样式支持
- 对象语法
- 数组语法
style的对象语法注意
禁止使用如下形式:
1<div v-bind:style="{ color: activeColor, fontSize: fontSize + 'rpx' }"></div> 2data: { 3 activeColor: 'red', 4 fontSize: 30 5}
1<div v-bind:style="{ color: activeColor, fontSize: fontSize + 'px' }"></div> 2data: { 3 activeColor: 'red', 4 fontSize: 30 5} 6 7请修改为如下形式: 8```html 9<div v-bind:style="{ color: activeColor, fontSize: fontSize }"></div> 10data: { 11 activeColor: 'red', 12 fontSize: '30rpx' 13}
即不能将数值和rpx分离,否则loader无法解析。
1<div v-bind:style="{ color: activeColor, fontSize: fontSize }"></div> 2data: { 3 activeColor: 'red', 4 fontSize: '30px' 5}
即不能将数值和px分离,否则loader无法解析。
示例(以vue工程为例)
1<template> 2 <div class="root" v-bind:class="{ active: isActive }" v-bind:style="{ fontSize: fontSize }"></div> 3</template> 4<script> 5export default { 6 data() { 7 return { 8 isActive: true, 9 fontSize: '30rpx' 10 } 11 } 12}; 13</script> 14<style> 15.root{ 16 width:100%; 17 height:87rpx;/*设计高度是多少,此处就填写多少*/ 18} 19.active{ 20 font-size:20rpx; 21} 22</style>
or
1<template> 2 <div class="root" v-bind:class="{ active: isActive }" v-bind:style="{ fontSize: fontSize }"></div> 3</template> 4<script> 5export default { 6 data() { 7 return { 8 isActive: true, 9 fontSize: '30px' 10 } 11 } 12}; 13</script> 14<style> 15.root{ 16 width:100%; 17 height:87px;/*设计高度是多少,此处就填写多少*/ 18} 19.active{ 20 font-size:20px; 21} 22</style>
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
Found 0/4 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Score
3
/10
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More