Skip to content

外部css引用,windows下路径问题 #186

@codeteenager

Description

@codeteenager

您好,在编译css的时候,如果@import了外部的css,mac下没有问题,windows下路径会生成\格式的,目前找到了源码原因,在build/src/compiler/style/style.js中
const importPlugin = postcss.plugin('postcss-import-plugin', function (opts = {}) {
let {cssExt} = opts;
cssExt = '.' + cssExt;
return function (root, result) {
root.walkAtRules('import', rule => {
try {
let params = JSON.parse(rule.params);
params = changeExt(params, cssExt);
rule.replaceWith(postcss.atRule({name: 'import', params: JSON.stringify(params)}));
} catch (e) {
throw new Error('[postcss] parse import rule fail: ' + e.message);
}
});
};
});
然后修改后缀名的方法changeExt,

function changeExt(filePath, ext) {
ext = ext[0] === '.' ? ext : ('.' + ext);
const { dir, name } = path.parse(filePath);
filePath = path.format({ dir, name, ext });
return filePath;
}
这个方法出现问题,path.format中windows下重新拼接文件时,路径分隔符是windows下的分隔符。

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions