LESS @import:将路径传递给lessc

Mar*_*ing 7 css less

我想在父主题和子主题中使用LESS样式表,其中大多数样式表信息由父项指定,子项只是覆盖了一些文件.这可以使用Ruby版本的LESS,如下所示:

var parser = new(less.Parser)({
    paths: ['.', './lib'], // Specify search paths for @import directives
    filename: 'style.less' // Specify a filename, for better error messages
});
Run Code Online (Sandbox Code Playgroud)

但是可以使用命令行编译器lessc吗?我想说:

$ lessc --path=".;../parent" style.less
Run Code Online (Sandbox Code Playgroud)

Wil*_*hes 6

看一下lessc源代码:

    case 'include-path':
        options.paths = match[2].split(':')
            .map(function(p) {
                if (p && p[0] == '/') {
                    return path.join(path.dirname(input), p);
                } else if (p) {
                    return path.join(process.cwd(), p);
                }
            });
        break;
Run Code Online (Sandbox Code Playgroud)

您可以将多个路径传递给lessc.因此,您的示例的正确语法是:

lessc --include-path=".:../parent" style.less
Run Code Online (Sandbox Code Playgroud)


hok*_*oka 4

马库斯

您可以使用 --include-path 开关。

lessc --include-path=./inc/ main.less
Run Code Online (Sandbox Code Playgroud)

请注意,它需要相对于 lessc 正在执行的路径。