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

Change the default behavior of "@import" to only import once. #1010

Closed
wants to merge 2 commits into from
Closed

Change the default behavior of "@import" to only import once. #1010

wants to merge 2 commits into from

Conversation

ljharb
Copy link
Contributor

@ljharb ljharb commented Oct 30, 2012

  • Change the default behavior of "@import" to only import once.
  • Add @import-multiple if for some insane reason you want multiple imports.
  • Continue to support @import-once for backwards compatibility.
  • Fixes Import Each Less File Only Once #212.

- Add @import-multiple if for some insane reason you want multiple imports.
- Continue to support @import-once for backwards compatibility.
- Fixes #212.

if (dir && (path = $(this.entities.quoted) || $(this.entities.url))) {
features = $(this.mediaFeatures);
if ($(';')) {
return new(tree.Import)(path, imports, features, (dir[1] === 'once'), index);
var importOnce = dir[1] !== 'multiple';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is a spacing issue here

@lukeapage
Copy link
Member

just the one minor issue, otherwise its +1 from me. Will pull if no-one else disagrees.

@dmcass
Copy link
Contributor

dmcass commented Nov 2, 2012

Just thought I'd note here the one insane reason that I can think of for wanting to import the same file more than once (and why I'm glad you're keeping @import-multiple). I'm not sure if this can be addressed in a different way, but if anyone has suggestions I'd love to hear them. Imports can contain variable assignments, and if you want different variable values at different scopes, using an import to reevaluate the values for the current scope is actually quite helpful.

Quick example:
dynamic.less

@bar: @foo * 6px;

main.less

@foo: 2;
@import "dynamic";

.baz {
    width: @foo;      /* 12px */
}

@media only screen and (min-width: 600px) {
    @foo: 5;
    @import "dynamic";

    .baz {
        width: @foo;  /* 30px */
    }
}

Also, this is 👍 from me.

@ljharb
Copy link
Contributor Author

ljharb commented Nov 2, 2012

@dmcass thanks for the explanation - personally I'd think that's way too much logic in CSS, and I'd rather have dynamic.less have @bar: 6px; and then in all the clients use @foo * @bar and then use @import-once. But to each their own, as long as there's a sane default.

@dmcass
Copy link
Contributor

dmcass commented Nov 2, 2012

@ljharb totally agree for the example I gave, but that's much simpler than the actual case where I would use something like that, when multiple variables and mixins change values based on another one with much more complicated math.

@matthew-dean
Copy link
Member

I see the theoretical case here, but to me, the complexity it adds just lends more weight to importing once, so that no one ever ever does this. ;-)

@Soviut
Copy link

Soviut commented Nov 3, 2012

I'd have to agree. Especially if an @import-multiple construct is created as a fallback.

@lukeapage
Copy link
Member

pushed to 1.4.0

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

Successfully merging this pull request may close these issues.

Import Each Less File Only Once
5 participants