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

@import (css) "file.css" puts the css at the top of the output #2440

Closed
thehung2224 opened this issue Feb 7, 2015 · 8 comments
Closed

@import (css) "file.css" puts the css at the top of the output #2440

thehung2224 opened this issue Feb 7, 2015 · 8 comments

Comments

@thehung2224
Copy link

Take the following less file, call it style.less:

/*------------------------------------*\
    #IMPORT
\*------------------------------------*/

/**
 * CSS files
 */

@import (css) "../css/bootstrap.css";

Look at the generated style.css then I see bootstrap css file at the top, followed by the comments.

How do I fix it? Thanks in advance.

@lukeapage
Copy link
Member

Hrmm, its always been like this it looks like. Its caused by the code

https://github.com/less/less.js/blob/master/lib/less/tree/ruleset.js#L338

@seven-phases-max @SomMeri

Looking at the history, It seems the logic over separating rulesets and rules is quite old. I am wondering how much is valid. Surely all we want to do is a) float imports statements above non comment statements b) float charsets above everything. Can you think of any reasons why anything else needs to be moved around? If we are not in root, what would need moving?

I'm in the process of refactoring it out and looks like all existing tests would still pass..

@seven-phases-max
Copy link
Member

I'm pretty sure nothing except what you listed needs to be moved.

The only weird thing is probably:

div {
    @import "something.css";
    @charset UTF-8;
}

but I guess this can be left as-is (just as it is now) because this code does not make any sense after all.

@matthew-dean
Copy link
Member

So, to clarify, is the bug simply that the @import rule is placed above the comment?

@seven-phases-max For your last example, I agree it probably doesn't need to be moved as we can't really know what the intent was of that invalid code. However it might be nice if any non-hoistable css @imports or things like duplicate (or maybe just conflicting) @charsets would generate a warning.

@seven-phases-max
Copy link
Member

So, to clarify, is the bug simply that the @import rule is placed above the comment?

Yep.`

lukeapage added a commit that referenced this issue Mar 21, 2015
@matthew-dean
Copy link
Member

Boom, @lukeapage already fixed it (in accordance to prophecy).

@SomMeri
Copy link
Member

SomMeri commented Mar 22, 2015

I am closing this, because it seem to be fixed by last two commits.

@SomMeri SomMeri closed this as completed Mar 22, 2015
@lukeapage lukeapage reopened this Mar 22, 2015
@lukeapage
Copy link
Member

I made a pr to see if anyone saw any problems. This will be closed automatically be the commit message when its merged.

@SomMeri
Copy link
Member

SomMeri commented Mar 22, 2015

@lukeapage Sorry, missed that it is pull request not a commit. I looked at the changes do not see problem with the pull request you made. I can not think of a reason why anything except charset and import should be moved.

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

No branches or pull requests

5 participants