LESS @import: Passing paths to lessc

2019-04-06 22:29发布

问题:

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.



标签: css less