-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Astro/Vite not adding global styles with <style lang="scss">
?
#12451
Comments
@flayks Please add a reproduction link. |
Here is a minimal reproduction link from a repo: You'll see in the
---
import "./Test.scss"
---
// Test.astro
<style lang="scss">
@use "./Test" as *;
</style>
// Test.scss
@use "../../styles/imports" as *;
// ... + styles
<style lang="scss">
@import "./Test";
</style> For some context and with a very similar setup, I use SCSS files with Svelte components using svelte-preprocess and <style lang="scss" src="./Component.scss"></style> But AFAIK Astro doesn't allow this I just feel that the additionalData is actually not imported using the |
This looks like a Vite issue. The problem here is that Vite is only adding ---
import "./Test.scss"
--- <style lang="scss">
@import "./Test";
</style> <style lang="scss" src="./Test.scss"></style> These will all make When you have <style lang="scss">
@use "./Test" as *;
</style> The entrypoint is the style tag itself (it creates a virtual module) so the additionalData is no longer added to Maybe it's worth reporting this to Vite if it's something worth fixing. However, I don't think there's much Astro can fix here. You may have to workaround adding the |
@bluwy Interesting. Thanks for investigating! I suppose how |
In practice we could support it but it requires some changes to the compiler due to some hardcoded things there, it won't rely on Vite. However, I don't know if this is something we should support yet, maybe worth opening a discussion at https://github.com/withastro/roadmap to gauge interest though. |
Righto, I made one, we'll see: withastro/roadmap#1061 |
Astro Info
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
It doesn't seem that Astro or Vite are adding global data to SCSS files for some reason, at least only if using
import '@styles/pages/weekly-page.scss'
in the<script>
tag.Importing stylesheets this way in Astro components is scoping it all (which I'm after), but I need to reimport my vars/functions/mixins in the file which feels a bit redundant 🤔
My Astro/Svelte config:
When importing styles like that on Svelte components using svelte-preprocess actually works:
What's the expected result?
I think it should include all the global data set in the config to all styling, without having to reimport this same file in each page/component
Link to Minimal Reproducible Example
https://stackblitz.com/~/github.com/flayks/astro-scss-global?file=src/components/Test/Test.astro
Participation
The text was updated successfully, but these errors were encountered: