0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-16 21:46:22 -05:00

Prevent inlining SCSS partials in dev (#5477)

This commit is contained in:
Bjorn Lu 2022-11-28 22:29:05 +08:00 committed by GitHub
parent c137752797
commit 5e693c2143
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 27 additions and 2 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Prevent inlining SCSS partials in dev

View file

@ -18,8 +18,15 @@ export async function getStylesForURL(
for await (const importedModule of crawlGraph(loader, viteID(filePath), true)) {
const ext = path.extname(importedModule.url).toLowerCase();
if (STYLE_EXTENSIONS.has(ext)) {
// The SSR module is possibly not loaded. Load it if it's null.
const ssrModule = importedModule.ssrModule ?? (await loader.import(importedModule.url));
let ssrModule: Record<string, any>;
try {
// The SSR module is possibly not loaded. Load it if it's null.
ssrModule = importedModule.ssrModule ?? (await loader.import(importedModule.url));
} catch {
// The module may not be inline-able, e.g. SCSS partials. Skip it as it may already
// be inlined into other modules if it happens to be in the graph.
continue;
}
if (
mode === 'development' && // only inline in development
typeof ssrModule?.default === 'string' // ignore JS module styles

View file

@ -49,6 +49,9 @@ import raw from '../styles/raw.css?raw'
<style lang="sass">
@import '../styles/linked.sass'
</style>
<style lang="scss">
@import '../styles/partial-main.scss';
</style>
</head>
<body>
<div class="wrapper">

View file

@ -0,0 +1,3 @@
@mixin make-red {
color: red;
}

View file

@ -0,0 +1,5 @@
// relies on partial-1. make sure astro don't inline this style.
.partial-test {
@include make-red;
}

View file

@ -0,0 +1,2 @@
@import './partial-1';
@import './partial-2';