-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Support specifying custom variables when calling lessc and less.js. #1655
Conversation
Both lessc and less.js can now be provided with global variables that all .less files will have immediate access to. This can be used to provide, for example, a base path for an @import, signed URLs offering temporary access to an image on S3, or anything else. lessc has two new parameters, --global-var and --modify-var. Both take a value of the form "varname=value". --global-var declares variables immediately before the content of the .less files, and --modify-var declares them after. --global-var is used when rules, imports, or other variables will depend on the provided variable. --modify-var is used to override a variable declared within the .less file. less.js's equivalent for global variables is less.globalVars. This can be set before loading less.js. There is no new requivalent to --modify-var, as less.modifyVars can be used for that purpose.
👍 |
@@ -64,7 +71,7 @@ args = args.filter(function (arg) { | |||
return false; | |||
} | |||
|
|||
if (match = arg.match(/^--?([a-z][0-9a-z-]*)(?:=([^\s]*))?$/i)) { arg = match[1] } | |||
if (match = arg.match(/^--?([a-z][0-9a-z-]*)(?:=(.*))?$/i)) { arg = match[1] } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whats the meaning of this change? so it goes from all non whitespace to characters?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it's to allow for whitespace characters. Otherwise, it's not possible to do expressions or any other sort of content containing whitespace. The whitespace will only end up in the value if explicitly quoted on the shell.
I looked through the other command line arguments and didn't see any that seemed they would be impacted by this change, and sys.argv already handles whitespace between arguments. I may have missed something important though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, makes sense.
👍 !!! |
Support specifying custom variables when calling lessc and less.js.
Doh! Again wrong number... Sorry! |
@lukeapage ping, I'd love to see this moved into less.js core. Can you give pointers for a PR? |
Both lessc and less.js can now be provided with global variables that
all .less files will have immediate access to. This can be used to
provide, for example, a base path for an
@import
, signed URLs offeringtemporary access to an image on S3, or anything else.
lessc has two new parameters,
--global-var
and--modify-var
. Both takea value of the form
"varname=value"
.--global-var
declares variablesimmediately before the content of the .less files, and
--modify-var
declares them after.
--global-var
is used when rules, imports, or other variables will dependon the provided variable.
--modify-var
is used to override a variable declared within the .lessfile.
less.js's equivalent for global variables is
less.globalVars
. This canbe set before loading less.js. There is no new equivalent to
--modify-var
, as less.modifyVars can be used for that purpose.Implements issue #731.