Skip to content

Commit 3fb3cd9

Browse files
fix(vite): route css import (#3438)
Fixes #3426
1 parent 016f94e commit 3fb3cd9

6 files changed

Lines changed: 72 additions & 4 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// @ts-ignore upstream issue https://github.com/denoland/deno/issues/30560
2+
import "./css_styles.css";
3+
4+
export default function Page() {
5+
return (
6+
<div>
7+
<div class="route">
8+
<h1>red text</h1>
9+
</div>
10+
</div>
11+
);
12+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
h1 {
2+
color: red;
3+
}

packages/plugin-vite/src/plugins/dev_server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export function devServer(): Plugin[] {
8181
url.pathname !== "/__inspect" &&
8282
res.headers.get("Content-Type")?.includes("text/html")
8383
) {
84-
const collected = await collectCss2(
84+
const collected = await collectCss(
8585
"fresh:client-entry",
8686
server.environments.client,
8787
);
@@ -132,7 +132,7 @@ export function devServer(): Plugin[] {
132132
];
133133
}
134134

135-
async function collectCss2(
135+
async function collectCss(
136136
id: string,
137137
env: DevEnvironment,
138138
) {

packages/plugin-vite/src/plugins/server_snapshot.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ export function serverSnapshot(options: ResolvedFreshViteConfig): Plugin[] {
351351
},
352352
transform: {
353353
filter: {
354-
id: /\.module\.(css|less|sass)(\?.*)?$/,
354+
id: /\.(css|less|sass|scss)(\?.*)?$/,
355355
},
356356
handler(_code, id, _options) {
357357
if (server) {

packages/plugin-vite/tests/build_test.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { expect } from "@std/expect";
2-
import { waitForText, withBrowser } from "../../fresh/tests/test_utils.tsx";
2+
import {
3+
waitFor,
4+
waitForText,
5+
withBrowser,
6+
} from "../../fresh/tests/test_utils.tsx";
37
import {
48
buildVite,
59
DEMO_DIR,
@@ -383,6 +387,33 @@ Deno.test({
383387
sanitizeResources: false,
384388
});
385389

390+
Deno.test({
391+
name: "vite build - route css import",
392+
fn: async () => {
393+
await launchProd(
394+
{ cwd: viteResult.tmp },
395+
async (address) => {
396+
await withBrowser(async (page) => {
397+
await page.goto(`${address}/tests/css`, {
398+
waitUntil: "networkidle2",
399+
});
400+
401+
await waitFor(async () => {
402+
const color = await page
403+
.locator("h1")
404+
// deno-lint-ignore no-explicit-any
405+
.evaluate((el) => window.getComputedStyle(el as any).color);
406+
expect(color).toEqual("rgb(255, 0, 0)");
407+
return true;
408+
});
409+
});
410+
},
411+
);
412+
},
413+
sanitizeOps: false,
414+
sanitizeResources: false,
415+
});
416+
386417
Deno.test({
387418
name: "vite build - remote island",
388419
fn: async () => {

packages/plugin-vite/tests/dev_server_test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,28 @@ Deno.test({
306306
sanitizeOps: false,
307307
});
308308

309+
Deno.test({
310+
name: "vite dev - route css import",
311+
fn: async () => {
312+
await withBrowser(async (page) => {
313+
await page.goto(`${demoServer.address()}/tests/css`, {
314+
waitUntil: "networkidle2",
315+
});
316+
317+
await waitFor(async () => {
318+
const color = await page
319+
.locator("h1")
320+
// deno-lint-ignore no-explicit-any
321+
.evaluate((el) => window.getComputedStyle(el as any).color);
322+
expect(color).toEqual("rgb(255, 0, 0)");
323+
return true;
324+
});
325+
});
326+
},
327+
sanitizeResources: false,
328+
sanitizeOps: false,
329+
});
330+
309331
Deno.test({
310332
name: "vite dev - remote island",
311333
fn: async () => {

0 commit comments

Comments
 (0)