Skip to content
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

Question about expected behavior of @import #297

Open
paulsheldrake opened this issue Aug 29, 2012 · 13 comments
Open

Question about expected behavior of @import #297

paulsheldrake opened this issue Aug 29, 2012 · 13 comments

Comments

@paulsheldrake
Copy link

I have a variables-mixins.less file and multiple other less files that use the mixins defined in that file. What I'm trying to do is have one large compiled css file as the result.

I've created another less file (styles.less) that has content like this

@import variables-mixins.less
@import less-file1.less
@import less-file2.less
@import less-file3.less
@import less-file4.less

What's happening is that now for every file that I import past the variables-mixins file, the rendered mixins from variables-mixins.less gets duplicated. So if i had a mixin called .rounded-corners(border-radius: 7px). The rendered file now has a class looking like this

.rounded-corners(
  border-radius: 7px;
  border-radius: 7px;
  border-radius: 7px;
  border-radius: 7px;
  border-radius: 7px;
)

I would have thought that it should just have the one border-radius style after compiling. Any have an idea of what I'm doing wrong?

@Bluestreak2k5
Copy link

I am not encountering this problem, have you tried importing this way:

Main Less file:

@import "reset";
@import "mixins";
@import "common";
@import "site";

each one of these refers to a .less file in the same folder and the main less file. Point your compiler at the main less file and it will compile it all into 1 CSS file.

This might have been fixed in a recent update, or it might be an unknown bug with the way it imports. I am using 0.3.6 version currently.

@leafo
Copy link
Owner

leafo commented Sep 24, 2012

similar to #305

less.js now has @import-once for exactly this problem. I'll be adding it shortly to lessphp

@gruvii
Copy link

gruvii commented Sep 27, 2012

+1

@barryvdh
Copy link
Contributor

Thanks, @import-once is exactly what I need :)

@barryvdh
Copy link
Contributor

barryvdh commented Nov 6, 2012

@leafo, they changed the default behavior to import once, and added import-multiple for the old behavior:
less/less.js@f27ea74

@davidenke
Copy link

+1
Would be very useful, even if it is not the default behavior...

@davidenke
Copy link

Anything new? Will it be in a release in the near future?

@rulatir
Copy link

rulatir commented Jan 13, 2013

+1000 badly!!!

@rulatir
Copy link

rulatir commented Mar 14, 2013

Version after version with this extremely important missing feature unimplemented...

@rulatir
Copy link

rulatir commented Mar 14, 2013

Apart from helping to avoid duplicates and boosting performance, this feature would also increase the expressiveness of the language. Consider this scenario:

//file wider-main-column.less

@import "variables"; //defines @main-column-width, among other stuff

@main-column-width: 800px; //attempts to override

@import "layout"; //imports "variables" too, un-overriding our attempted override

Versus this:

//file wider-main-column.less

@import-once "variables"; //defines @main-column-width, among other stuff

@main-column-width: 800px; //overrides

@import "layout"; //imports-once "variables", but we've already imported it, so our override stands, YAY!

@barryvdh
Copy link
Contributor

The behavior is changing in the new 1.4 version of Less.js:
https://github.com/cloudhead/less.js/blob/master/CHANGELOG.md

  • default behaviour of import is to import each file once.
  • You can specify options on imports to force it to behave as css or less @import (less) "file.css" will process the file as less

More info: less/less.js#1185 (comment)

@jimmymorrisuk
Copy link

Hi @leafo

You said "less.js now has @import-once for exactly this problem. I'll be adding it shortly to lessphp" however this was 9 months ago. Any news on when this might be coming?

Cheers

@rulatir
Copy link

rulatir commented Dec 8, 2013

When? When? When?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants