fix(vite): serve css imported in islands (#3272)
Fixes https://github.com/denoland/fresh/issues/3271
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
.root {
|
||||
color: red;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// @ts-ignore upstream issue https://github.com/denoland/deno/issues/30560
|
||||
import styles from "./CssModules.module.css";
|
||||
|
||||
export function CssModules() {
|
||||
return <h1 class={styles.root}>red text</h1>;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import { CssModules } from "../../islands/CssModules.tsx";
|
||||
|
||||
export default function Page() {
|
||||
return <CssModules />;
|
||||
}
|
||||
@@ -10,7 +10,8 @@
|
||||
},
|
||||
"compilerOptions": {
|
||||
"jsx": "precompile",
|
||||
"jsxImportSource": "preact"
|
||||
"jsxImportSource": "preact",
|
||||
"types": ["../../global.d.ts"]
|
||||
},
|
||||
"tasks": {
|
||||
"demo": "vite demo",
|
||||
|
||||
@@ -153,6 +153,7 @@ export function serverSnapshot(options: ResolvedFreshViteConfig): Plugin[] {
|
||||
name: def.name,
|
||||
server: id,
|
||||
browser: def.chunk ?? `/@id/fresh-island::${def.name}`,
|
||||
css: [],
|
||||
};
|
||||
});
|
||||
} else {
|
||||
@@ -206,11 +207,14 @@ export function serverSnapshot(options: ResolvedFreshViteConfig): Plugin[] {
|
||||
spec = spec.slice(1);
|
||||
}
|
||||
|
||||
const chunkCss = mod.css?.map((id) => `/${id}`) ?? [];
|
||||
|
||||
const name = namer.getUniqueName(specToName(id));
|
||||
islandMods.push({
|
||||
name,
|
||||
browser: spec,
|
||||
server: serverPath,
|
||||
css: chunkCss,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -326,3 +326,27 @@ Deno.test({
|
||||
sanitizeOps: false,
|
||||
sanitizeResources: false,
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
name: "vite build - island css modules",
|
||||
fn: async () => {
|
||||
await launchProd(
|
||||
{ cwd: viteResult.tmp },
|
||||
async (address) => {
|
||||
await withBrowser(async (page) => {
|
||||
await page.goto(`${address}/tests/css_modules`, {
|
||||
waitUntil: "networkidle2",
|
||||
});
|
||||
|
||||
const color = await page
|
||||
.locator("h1")
|
||||
// deno-lint-ignore no-explicit-any
|
||||
.evaluate((el) => window.getComputedStyle(el as any).color);
|
||||
expect(color).toEqual("rgb(255, 0, 0)");
|
||||
});
|
||||
},
|
||||
);
|
||||
},
|
||||
sanitizeOps: false,
|
||||
sanitizeResources: false,
|
||||
});
|
||||
|
||||
@@ -268,3 +268,24 @@ Deno.test({
|
||||
sanitizeResources: false,
|
||||
sanitizeOps: false,
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
name: "vite dev - island css modules",
|
||||
fn: async () => {
|
||||
await launchDevServer(tmp.dir, async (address) => {
|
||||
await withBrowser(async (page) => {
|
||||
await page.goto(`${address}/tests/css_modules`, {
|
||||
waitUntil: "networkidle2",
|
||||
});
|
||||
|
||||
const color = await page
|
||||
.locator("h1")
|
||||
// deno-lint-ignore no-explicit-any
|
||||
.evaluate((el) => window.getComputedStyle(el as any).color);
|
||||
expect(color).toEqual("rgb(255, 0, 0)");
|
||||
});
|
||||
});
|
||||
},
|
||||
sanitizeResources: false,
|
||||
sanitizeOps: false,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user