mirror of
https://github.com/less/less.js.git
synced 2026-01-22 13:48:03 -05:00
Add an --include-path option to lessc.
This adds an optional `--include-path=foo` argument to the command line lessc script. Paths are evaluated relative to the current working directory, so paths like `../foo`, `./bar` and `baz` all work just like you'd expect. Multiple paths can be supplied by separating them with colons, e.g. `--include-path=foo:../bar:/baz` The basedir of the input file is always in the include path because that just makes sense.
This commit is contained in:
committed by
Alexis Sellier
parent
2de86bd901
commit
aaedf96564
17
bin/lessc
17
bin/lessc
@@ -11,13 +11,14 @@ var args = process.argv.slice(1);
|
||||
var options = {
|
||||
compress: false,
|
||||
optimization: 1,
|
||||
silent: false
|
||||
silent: false,
|
||||
paths: []
|
||||
};
|
||||
|
||||
args = args.filter(function (arg) {
|
||||
var match;
|
||||
|
||||
if (match = arg.match(/^--?([a-z][0-9a-z-]*)$/i)) { arg = match[1] }
|
||||
if (match = arg.match(/^--?([a-z][0-9a-z-]*)(?:=([^\s]+))?$/i)) { arg = match[1] }
|
||||
else { return arg }
|
||||
|
||||
switch (arg) {
|
||||
@@ -40,6 +41,16 @@ args = args.filter(function (arg) {
|
||||
case 'compress':
|
||||
options.compress = true;
|
||||
break;
|
||||
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;
|
||||
case 'O0': options.optimization = 0; break;
|
||||
case 'O1': options.optimization = 1; break;
|
||||
case 'O2': options.optimization = 2; break;
|
||||
@@ -69,7 +80,7 @@ fs.readFile(input, 'utf-8', function (e, data) {
|
||||
}
|
||||
|
||||
new(less.Parser)({
|
||||
paths: [path.dirname(input)],
|
||||
paths: [path.dirname(input)].concat(options.paths),
|
||||
optimization: options.optimization,
|
||||
filename: input
|
||||
}).parse(data, function (err, tree) {
|
||||
|
||||
Reference in New Issue
Block a user