css3 - webstrom有px转rem的插件吗
大家讲道理
大家讲道理 2017-04-17 11:28:49
0
1
517

mac下如何转换单位呢,Sublime是有的?求大神

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(1)
小葫芦

You can use Nodejs to write a simple command line tool yourself.
You only need to master the simple synchronization file module and regular expressions~

var fs = require("fs")

function format(filePath, keywords) {
    //  同步读取文件内容
    var content = fs.readFileSync(filePath, "utf-8")

    var arr = content.split("\n")

    var count = 0

    for (var i = 0; i < arr.length; i++) {
        var value = arr[i]
        var temp
        temp = value.replace(/(\d+)px/g, function() {
            if (arguments[3].indexOf("@media") != -1 || arguments[3].indexOf("max") != -1 || arguments[3].indexOf("min") != -1) {
                 
            } else if (Number(arguments[1]) > 1) {
                count++;
                // 这里可以自己维护换算规则
                return Number(arguments[1]) / 100 + "rem"
            }

            return arguments[0]
        })

        if (temp != arr[i]) {
            arr.splice(i + 1, 0, temp)
        }
    }

    var result = arr.join("\n")

    var formatFilePath = filePath.replace(".", keywords + ".");

    fs.writeFile(formatFilePath, result, "utf-8", function(err) {
        if (err) console.log(err)
        console.log("change lines number: " + count)
    })
}

format("style.css", "_format");

Use node app.js (for example, you save the above code as app.js)
Then it will automatically calculate the style.css in the same path and calculate the px in it as rem. You can maintain it yourself. Conversion rules.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template