LESS @import: Passing paths to lessc

烂漫一生 提交于 2019-12-05 23:17:06

问题


I'd like to use LESS stylesheets in a parent and child theme, in which most of the stylesheet information is specified by the parent and the child simply overrides a few files. This is possible with the Ruby version of LESS like so:

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

but is it possible with the command line compiler lessc? I'd like to say:

$ lessc --path=".;../parent" style.less

回答1:


Looking at the lessc source code:

    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;

You can pass multiple paths to lessc. So the correct syntax for your example is:

lessc --include-path=".:../parent" style.less



回答2:


Marcus

There's a --include-path switch that you can use.

lessc --include-path=./inc/ main.less

Note, it needs to be relative to the path that lessc is executing in.



来源:https://stackoverflow.com/questions/7363079/less-import-passing-paths-to-lessc

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!