You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
varthrough=require('through2');module.exports=function(){returnthrough.obj(function(file,enc,cb){if(file.isNull()){this.push(file);returncb();}if(file.isStream()){this.emit('error',newgutil.PluginError(PLUGIN_NAME,'Streaming not supported'));returncb();}varreg=/(\d+)px/ig;functionmed(){vars1=arguments[1];returnparseFloat(s1)/100+'rem'}varcontent=file.contents.toString().replace(reg,med);file.contents=newBuffer(content);this.push(file);cb();});};
作用就是把px转换成rem,今天加班收获不少O(∩_∩)O哈哈~

file.contents.toString()
这句话的意思就是获取文件的内容,然后转换成字符串放在这https://github.com/ralcen/jsCode/blob/master/gulp_bulid/gulp-pxtworem.js
为了匹配小数的情况,更新了一下正则表达式
var reg = /(\d+\.\d+)px|(\d+)px/ig;
med函数也有所更改,具体看github里面的代码
#2015-07-12
The text was updated successfully, but these errors were encountered: