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:
parent
c137752797
commit
5e693c2143
6 changed files with 27 additions and 2 deletions
5
.changeset/twelve-kings-rest.md
Normal file
5
.changeset/twelve-kings-rest.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Prevent inlining SCSS partials in dev
|
|
@ -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
|
||||
|
|
|
@ -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">
|
||||
|
|
3
packages/astro/test/fixtures/0-css/src/styles/_partial-1.scss
vendored
Normal file
3
packages/astro/test/fixtures/0-css/src/styles/_partial-1.scss
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
@mixin make-red {
|
||||
color: red;
|
||||
}
|
5
packages/astro/test/fixtures/0-css/src/styles/_partial-2.scss
vendored
Normal file
5
packages/astro/test/fixtures/0-css/src/styles/_partial-2.scss
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
// relies on partial-1. make sure astro don't inline this style.
|
||||
|
||||
.partial-test {
|
||||
@include make-red;
|
||||
}
|
2
packages/astro/test/fixtures/0-css/src/styles/partial-main.scss
vendored
Normal file
2
packages/astro/test/fixtures/0-css/src/styles/partial-main.scss
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
@import './partial-1';
|
||||
@import './partial-2';
|
Loading…
Reference in a new issue