[Early Feedback] External Style Import Unification #28
Replies: 6 comments 19 replies
-
For HTML For CSS |
Beta Was this translation helpful? Give feedback.
-
Another possible way to bring in css is from an |
Beta Was this translation helpful? Give feedback.
-
There's a 4th way: ---
import xUrl './X.css?url';
---
<link rel="stylesheet" href={xUrl}> |
Beta Was this translation helpful? Give feedback.
-
@FredKSchott One thorn in my side right now is that I don't see any good documentation in 0.21, and some inconsistent behavior, with regards to
The main concern that I have with the proposal as given here is that form # 4, which you are proposing to eliminate, is the only form that I believe works with snowpack aliases today. As a result, eliminating that form without providing a replacement, it looks like we would complicate/uglify inclusion of library CSS? I would like to see this addressed at some point, and this RFC seems like it might be a good place to fold that in — but I defer to you wrt the scope of this discussion. |
Beta Was this translation helpful? Give feedback.
-
I think it would be good to include in the proposal a grouping of use-cases and how those would be achieved. Some examples:
|
Beta Was this translation helpful? Give feedback.
-
Assuming the ---
import one from './styles/one.css?url'
import two from './styles/two.css?url'
---
<link rel="stylesheet" href={one}>
<link rel="stylesheet" href={two}>
For the above reasons I think it makes more sense that, if we support this import syntax, they not be bundled. And instead treated like image assets where it is hashed and moved into |
Beta Was this translation helpful? Give feedback.
-
There are currently
threefour different ways to bring an external CSS file onto the page:<link href={Astro.resolve("./X.css")} />
Update: Not supported by Vite<link rel="stylesheet" href={xUrl}> // import xUrl from './X.css?url';
<style>@import './X.css';</style>
import './X.css'; // in Astro component frontmatter
It's difficult for us as maintainers to document, test and support so many different way to do things. Each method may support different features, or imply some different behavior. It's equally difficult for users to understand which is the "right" way to do things.
Now that #12 and #26 exist, I think we can simplify this somewhat. Here's my proposal, which is following the same logic of #12 and #26 around
<head>
behavior and not adding magic (like bundling) to existing HTML elements (like<link>
) without user opt-in.Rough Proposal
1. ✅
<link href="/global.css" />
or<link href="https://..." />
/public
or external CSS file.<link>
tag in the browser.Astro.resolve()
! (see other options below)public/
or an external CSS URL. This will not be bundled/optimized.src/
, see option 2.<head>
2. ❌
<link rel="stylesheet" href={xUrl}> // import xUrl from './X.css?url';
xUrl
, but it still won't bundle this CSS file as you would expect. This means that the resolved URL might not actually exist in the final build, if that file had been bundled.3. ✅
<style @component>@import './X.css';</style>
Note: I'm using
@component
here in explicit reference to #12, but if that is unfamiliar then ignore it for now. This is essentially the same as our current v0.20 default scoping and bundling behavior of Astro component<style>
.<style @component>
element is scoped.@import './X.css';
will inherit from all Vite support, including aliases and npm package@import
support.4. ✅
import './X.css'; // in Astro component frontmatter
Feedback?
Beta Was this translation helpful? Give feedback.
All reactions