-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Allow passing variables in from command-line #731
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
Comments
👍 |
just write them to a file and include it? |
Toolchain integration would be much easier if @agatronic How do you easily write out a file from a makefile? (No echo hax) |
+1 Extra special bonus points if the command-line provided variable can explicitly override one defined in your source .less files. Use case for me is:
Edited to add: the reason for overriding like this, if not clear from the above, is that I can have a default value for use by the in-browser development mode, and override the value with the full base path to a CDN during compilation when deploying. |
@twoolie Echo hacks are still better than awk/sed hacks. |
I was just going to create this as a feature request, this is a great idea. Huge thumbs-up from me. An example use case would be to use this to define variables in external JSON files, say representing themes, swatches, and so on, and then use build configuration to mix and match. The power of this feature is that it makes LESS more interesting to 3rd-party build systems that use Less.js. If you want real-world examples of something similar, look at Shopify themes. They use liquid for templating, and they use LESS for styles. And when you create a theme you put all of your theme variables into JSON. What's cool is that you can put some variables in JSON and some directly in the styles. Once you start doing it that way you begin to see patterns of why you would always put certain variables in JSON and others in LESS. {
"basePath": "../base/path"
} However, I don't like the override concept. I think variables defined this way would be considered "global variables" and would be overridden by anything defined inside the LESS files themselves. It needs to be black and white like that or it's too complicated. |
👍 |
@jonschlinkert re: override concept. what you say would also match the browser variable injection. will target 1.4.1 |
👍 this will be a huge feature! can't wait |
Related to #1374. |
We had a need for this in our product (Review Board) as well. Specifically, we needed to be able to define global variables that a .less file could use as a path for imports, both during compilation time with lessc, and during development using less.js. Along with this, we needed the equivalent of I started playing around with this and developed a change. I know the guidelines say to discuss the design before working on any code, but I took our requirements as an opportunity to learn the codebase and test out designs on our product's side, so I have some code I'll be submitted for your review/feedback anyway. Let me know if there are better ways of doing what I'm doing, or if you'd prefer a different design. I'll go over what I've put together. lessc I've added two new arguments to lessc:
For example, using global variables with a .less file that depends on $ lessc --global-var="static-url='/static/'" site.less site.css Or, if the .less file defined a default for testing that you'd want to override: $ lessc --modify-var="static-url='http://cdn.example.com/'" site.less site.css Multiple variables of either type can be specified by passing additional less.js I also added a new option to less.js's Here's an example with a Django template: <script>
less = {
globalVars: {
'static-url': '{{settings.STATIC_URL}}'
}
}
</script> Use cases There are some good use cases listed in this bug report, and in some other related reports. Ours is similar to the other base path use-cases. Essentially, we've standardized on less for all static media for extensions built for Review Board, and needed a way to provide some configuration-related variables to all bundled and extension-provided .less files, for the base path and for other bits of build-time configuration. The variables we prepare are largely for the When packaging, depending on the configuration of the server, certain variables may be overridden, and for this we'd use |
Thanks, Luke! |
Thanks Luke! Christoph Hochstrasser ❖ http://twitter.com/hochchristoph ❖ http://christophh.net ❖ On Sat, Nov 16, 2013, at 12:40 AM, chipx86 wrote: Thanks, Luke! — Reply to this email directly or [1]view it on GitHub. References |
Would it be possible to pass in arbitary vars from commandline?
lessc {infile} --variable="@static_url: \"{static_url}\"" > {outfile}
or
lessc {infile} --static_url=/static/ > {outfile}
The text was updated successfully, but these errors were encountered: