Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
codeteenager opened this issue Nov 22, 2019 · 0 comments
Open

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

codeteenager opened this issue Nov 22, 2019 · 0 comments

Comments

@codeteenager
Copy link

您好,在编译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下的分隔符。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant