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

Prevent inlining SCSS partials in dev #5477

Merged
merged 1 commit into from
Nov 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/twelve-kings-rest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Prevent inlining SCSS partials in dev
11 changes: 9 additions & 2 deletions packages/astro/src/core/render/dev/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions packages/astro/test/fixtures/0-css/src/pages/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down
3 changes: 3 additions & 0 deletions packages/astro/test/fixtures/0-css/src/styles/_partial-1.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@mixin make-red {
color: red;
}
5 changes: 5 additions & 0 deletions packages/astro/test/fixtures/0-css/src/styles/_partial-2.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// relies on partial-1. make sure astro don't inline this style.

.partial-test {
@include make-red;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@import './partial-1';
@import './partial-2';