fix(vite): route css import (#3438)
Fixes https://github.com/denoland/fresh/issues/3426
This commit is contained in:
@@ -0,0 +1,12 @@
|
|||||||
|
// @ts-ignore upstream issue https://github.com/denoland/deno/issues/30560
|
||||||
|
import "./css_styles.css";
|
||||||
|
|
||||||
|
export default function Page() {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<div class="route">
|
||||||
|
<h1>red text</h1>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
h1 {
|
||||||
|
color: red;
|
||||||
|
}
|
||||||
@@ -81,7 +81,7 @@ export function devServer(): Plugin[] {
|
|||||||
url.pathname !== "/__inspect" &&
|
url.pathname !== "/__inspect" &&
|
||||||
res.headers.get("Content-Type")?.includes("text/html")
|
res.headers.get("Content-Type")?.includes("text/html")
|
||||||
) {
|
) {
|
||||||
const collected = await collectCss2(
|
const collected = await collectCss(
|
||||||
"fresh:client-entry",
|
"fresh:client-entry",
|
||||||
server.environments.client,
|
server.environments.client,
|
||||||
);
|
);
|
||||||
@@ -132,7 +132,7 @@ export function devServer(): Plugin[] {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
async function collectCss2(
|
async function collectCss(
|
||||||
id: string,
|
id: string,
|
||||||
env: DevEnvironment,
|
env: DevEnvironment,
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -351,7 +351,7 @@ export function serverSnapshot(options: ResolvedFreshViteConfig): Plugin[] {
|
|||||||
},
|
},
|
||||||
transform: {
|
transform: {
|
||||||
filter: {
|
filter: {
|
||||||
id: /\.module\.(css|less|sass)(\?.*)?$/,
|
id: /\.(css|less|sass|scss)(\?.*)?$/,
|
||||||
},
|
},
|
||||||
handler(_code, id, _options) {
|
handler(_code, id, _options) {
|
||||||
if (server) {
|
if (server) {
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
import { expect } from "@std/expect";
|
import { expect } from "@std/expect";
|
||||||
import { waitForText, withBrowser } from "../../fresh/tests/test_utils.tsx";
|
import {
|
||||||
|
waitFor,
|
||||||
|
waitForText,
|
||||||
|
withBrowser,
|
||||||
|
} from "../../fresh/tests/test_utils.tsx";
|
||||||
import {
|
import {
|
||||||
buildVite,
|
buildVite,
|
||||||
DEMO_DIR,
|
DEMO_DIR,
|
||||||
@@ -383,6 +387,33 @@ Deno.test({
|
|||||||
sanitizeResources: false,
|
sanitizeResources: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Deno.test({
|
||||||
|
name: "vite build - route css import",
|
||||||
|
fn: async () => {
|
||||||
|
await launchProd(
|
||||||
|
{ cwd: viteResult.tmp },
|
||||||
|
async (address) => {
|
||||||
|
await withBrowser(async (page) => {
|
||||||
|
await page.goto(`${address}/tests/css`, {
|
||||||
|
waitUntil: "networkidle2",
|
||||||
|
});
|
||||||
|
|
||||||
|
await waitFor(async () => {
|
||||||
|
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)");
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
sanitizeOps: false,
|
||||||
|
sanitizeResources: false,
|
||||||
|
});
|
||||||
|
|
||||||
Deno.test({
|
Deno.test({
|
||||||
name: "vite build - remote island",
|
name: "vite build - remote island",
|
||||||
fn: async () => {
|
fn: async () => {
|
||||||
|
|||||||
@@ -306,6 +306,28 @@ Deno.test({
|
|||||||
sanitizeOps: false,
|
sanitizeOps: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Deno.test({
|
||||||
|
name: "vite dev - route css import",
|
||||||
|
fn: async () => {
|
||||||
|
await withBrowser(async (page) => {
|
||||||
|
await page.goto(`${demoServer.address()}/tests/css`, {
|
||||||
|
waitUntil: "networkidle2",
|
||||||
|
});
|
||||||
|
|
||||||
|
await waitFor(async () => {
|
||||||
|
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)");
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
sanitizeResources: false,
|
||||||
|
sanitizeOps: false,
|
||||||
|
});
|
||||||
|
|
||||||
Deno.test({
|
Deno.test({
|
||||||
name: "vite dev - remote island",
|
name: "vite dev - remote island",
|
||||||
fn: async () => {
|
fn: async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user