-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Open
Description
用的非uniapp和微信小程序技术栈,这时需要将默认的uniapp的upx单位转换成浏览器能识别的rpx或clamp , vw单位。比较传统的办法就是,嗯
复制main.css的文件到控制台,复制的时候建立一个变量,使用模版字符串进行赋值,如:
var str = `/* ColorUi for MP-weixin v2.1.4 | by 文晓港 2019年4月25日19:15:42 ....`;如果看到报错:
Octal escape sequences are not allowed in template strings.
那么先把这个样式复制到vscode中,进行查找替换 把 "" 替换成 "\" (多一个“"进行转义处理)
然后写上这样的正则:
str.replace(/(\d*)(upx)/g,function(match,p1,p2){
console.log(match ,p1,p2);
return (p1 * 0.04) + 'rem'; //这里的参数系数,如果转换成你的单位用自己的布局规划计算得出,我这里是0.04(20upx == 1.5rem)
});然后控制台得到一大串字符串,复制再粘贴回vscode进行编辑,接下来又是复制替换操作:
1.点击正则替换(”.“操作按钮),替换全部的"\\n" 为 “\n“
2. 点击正则替换(”.“操作按钮),替换全部的"\\t" 为 “\t“
3. 删掉行首"`" 字符
4. 删掉行尾"`."字符
搞定!
webpack玩家可以找找postcss看看有没有upx转rem或px的插件,我是没有找到(只有px转rem或其他单位的)
Metadata
Metadata
Assignees
Labels
No labels