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

CSS @imports are not the first rule in the css output file #5484

Closed
Guichaguri opened this issue Dec 15, 2020 · 0 comments · Fixed by #6696
Closed

CSS @imports are not the first rule in the css output file #5484

Guichaguri opened this issue Dec 15, 2020 · 0 comments · Fixed by #6696

Comments

@Guichaguri
Copy link

Guichaguri commented Dec 15, 2020

🐛 bug report

The @import rule is supposed to be the first rule in a CSS file. When two css files are combined, the @import rule is kept in the import order and not moved to the start of the file.

From the official specs (present since CSS2):

Any @import rules must precede all other valid at-rules and style rules in a style sheet (ignoring @charset), or else the @import rule is invalid.

https://drafts.csswg.org/css-cascade-4/#at-ruledef-import

🎛 Configuration (.babelrc, package.json, cli command)

import 'style.css'
import 'another.css'
/* style.css */
body {
    ...
}
/* another.css */
@import url('https://fonts.googleapis.com/icon?family=Material+Icons');

div {
    ...
}

🤔 Expected Behavior

/* output css file */

@import url('https://fonts.googleapis.com/icon?family=Material+Icons');

body {
    ...
}

div {
    ...
}

😯 Current Behavior

/* output css file */

body {
    ...
}

@import url('https://fonts.googleapis.com/icon?family=Material+Icons');

div {
    ...
}

💁 Possible Solution

The @import rules should be detected and, either moved to the start of the file or splitted into its own file.

🔦 Context

Each component of my app contains its own css file, by changing the order the components are loaded, the @import rule might not be the first rule in the final css file, meaning it won't work at all.

I used to build the same codebase using Webpack which worked well with weirdly-ordered css imports, this is the only issue I've seen after moving over to Parcel.

🌍 Your Environment

Software Version(s)
Parcel 2.0.0-beta.1 (I've also seen the issue in v1)
Node 13.5.0
npm/Yarn Yarn 1.21.1
Operating System Windows 10 x64
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants