@import inside a selector (feature request)
See original GitHub issueAllowing imports inside of selectors would open up an awesome collection of possibilities for code reuse and style scoping. Something like:
.foo{
@import "bar";
}
Would prove especially useful for creating less modules for CSS backed widgets. For example, if I author e.g., AutoRotator and a StackContainer and had the ability to nest imports inside selectors, then I could do:
# AutoRotator/pane.less
.pane{
border: 1px solid gray;
width: 300px;
/* etc. ... */
}
# StackContainer/pane.less
.pane{
border: 1px solid orange;
width: 200px;
/* etc. ... */
}
And the user of either library would be able to decide the scope of the various styles like:
# main.less
.myRotator {
@import "AutoRotator/pane";
}
# main.less
.myStack {
@import "StackContainer/pane";
}
Notice how simple the selectors seem inside the files. I think this basically just simulates http://www.w3.org/TR/css3-namespace/
Issue Analytics
- State:
- Created 12 years ago
- Reactions:10
- Comments:12 (4 by maintainers)
Top Results From Across the Web
import - CSS: Cascading Style Sheets - MDN Web Docs
The @import CSS at-rule is used to import style rules from other valid stylesheets. An @import rule must be defined at the top...
Read more >HTML Imports - web.dev
Imports provide convention for bundling HTML/CSS/JS (even other HTML Imports) into a single deliverable. It's an intrinsic feature, but a powerful one.
Read more >If '<selector>' is an Angular component, then verify that it is ...
When I added this import the error message disappeared. Check all imports inside the component. Hope it helps someone.
Read more >@import and @require | Stylus
@import works by iterating an array of directories, and checking if this file lives in any of them (similar to node's require.paths )....
Read more >Possibiliti to change selector order - Web Scraper
I recently ran into this same requirement. I did use the export and import features to re-order the JSON. As a developer that's...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ve found a dirty hack to allow namespaced imports. Just comment the following lines:
https://github.com/cloudhead/less.js/blob/master/lib/less/tree/ruleset.js#L20
and
https://github.com/cloudhead/less.js/blob/master/lib/less/tree/ruleset.js#L27
to look like
But I have no clue what this also affects on compiling. I’ve done a small test with bootstrap from Twitter:
Compiles down to:
And It has worked in my case. Can anyone confirm this on a larger project?
@cloudhead Why is importing only executed on the root level? And why is
ruleset.allowImports
alwaysundefined
and how can I overwrite it to be alwaystrue
? 😃Thanks
Ok, done… it’s on by default, as performance hit was not that high… option to disable is
--strict-imports