feat: add native TailwindCSS plugin (#2056)
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"lock": false,
|
||||
"imports": {
|
||||
"$fresh/": "../../",
|
||||
"preact": "https://esm.sh/preact@10.15.1",
|
||||
"preact/": "https://esm.sh/preact@10.15.1/"
|
||||
},
|
||||
"compilerOptions": {
|
||||
"jsx": "react-jsx",
|
||||
"jsxImportSource": "preact"
|
||||
}
|
||||
}
|
||||
Executable
+5
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env -S deno run -A --watch=static/,routes/
|
||||
|
||||
import dev from "$fresh/dev.ts";
|
||||
|
||||
await dev(import.meta.url, "./main.ts");
|
||||
@@ -0,0 +1,8 @@
|
||||
import { defineConfig } from "$fresh/server.ts";
|
||||
import { middlewarePlugin } from "./plugins/middleware.ts";
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [
|
||||
middlewarePlugin(),
|
||||
],
|
||||
});
|
||||
@@ -0,0 +1,19 @@
|
||||
// DO NOT EDIT. This file is generated by Fresh.
|
||||
// This file SHOULD be checked into source version control.
|
||||
// This file is automatically updated during development when running `dev.ts`.
|
||||
|
||||
import * as $_middleware from "./routes/_middleware.ts";
|
||||
import * as $index from "./routes/index.tsx";
|
||||
|
||||
import { Manifest } from "$fresh/server.ts";
|
||||
|
||||
const manifest = {
|
||||
routes: {
|
||||
"./routes/_middleware.ts": $_middleware,
|
||||
"./routes/index.tsx": $index,
|
||||
},
|
||||
islands: {},
|
||||
baseUrl: import.meta.url,
|
||||
} satisfies Manifest;
|
||||
|
||||
export default manifest;
|
||||
@@ -0,0 +1,11 @@
|
||||
/// <reference no-default-lib="true" />
|
||||
/// <reference lib="dom" />
|
||||
/// <reference lib="dom.iterable" />
|
||||
/// <reference lib="dom.asynciterable" />
|
||||
/// <reference lib="deno.ns" />
|
||||
|
||||
import { start } from "$fresh/server.ts";
|
||||
import manifest from "./fresh.gen.ts";
|
||||
import config from "./fresh.config.ts";
|
||||
|
||||
await start(manifest, config);
|
||||
@@ -0,0 +1,18 @@
|
||||
import { Plugin } from "$fresh/server.ts";
|
||||
|
||||
export function middlewarePlugin(): Plugin {
|
||||
return {
|
||||
name: "mw-plugin",
|
||||
middlewares: [
|
||||
{
|
||||
path: "/",
|
||||
middleware: {
|
||||
handler: (req, ctx) => {
|
||||
console.log("hey", req.url);
|
||||
return ctx.next();
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
import { MiddlewareHandlerContext } from "$fresh/server.ts";
|
||||
|
||||
export async function handler(req: Request, ctx: MiddlewareHandlerContext) {
|
||||
console.log(ctx.destination);
|
||||
console.log(req.url);
|
||||
const resp = await ctx.next();
|
||||
return resp;
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
export default function Page() {
|
||||
return <h1>foo</h1>;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"lock": false,
|
||||
"imports": {
|
||||
"$fresh/": "../../",
|
||||
"preact": "https://esm.sh/preact@10.15.1",
|
||||
"preact/": "https://esm.sh/preact@10.15.1/",
|
||||
"tailwindcss": "npm:tailwindcss@3.3.5"
|
||||
},
|
||||
"compilerOptions": {
|
||||
"jsx": "react-jsx",
|
||||
"jsxImportSource": "preact"
|
||||
}
|
||||
}
|
||||
Executable
+6
@@ -0,0 +1,6 @@
|
||||
#!/usr/bin/env -S deno run -A --watch=static/,routes/
|
||||
|
||||
import dev from "$fresh/dev.ts";
|
||||
import config from "./fresh.config.ts";
|
||||
|
||||
await dev(import.meta.url, "./main.ts", config);
|
||||
@@ -0,0 +1,8 @@
|
||||
import { defineConfig } from "$fresh/server.ts";
|
||||
import tailwind from "$fresh/plugins/tailwind.ts";
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [
|
||||
tailwind(),
|
||||
],
|
||||
});
|
||||
@@ -0,0 +1,19 @@
|
||||
// DO NOT EDIT. This file is generated by Fresh.
|
||||
// This file SHOULD be checked into source version control.
|
||||
// This file is automatically updated during development when running `dev.ts`.
|
||||
|
||||
import * as $_app from "./routes/_app.tsx";
|
||||
import * as $index from "./routes/index.tsx";
|
||||
|
||||
import { Manifest } from "$fresh/server.ts";
|
||||
|
||||
const manifest = {
|
||||
routes: {
|
||||
"./routes/_app.tsx": $_app,
|
||||
"./routes/index.tsx": $index,
|
||||
},
|
||||
islands: {},
|
||||
baseUrl: import.meta.url,
|
||||
} satisfies Manifest;
|
||||
|
||||
export default manifest;
|
||||
@@ -0,0 +1,11 @@
|
||||
/// <reference no-default-lib="true" />
|
||||
/// <reference lib="dom" />
|
||||
/// <reference lib="dom.iterable" />
|
||||
/// <reference lib="dom.asynciterable" />
|
||||
/// <reference lib="deno.ns" />
|
||||
|
||||
import { start } from "$fresh/server.ts";
|
||||
import manifest from "./fresh.gen.ts";
|
||||
import config from "./fresh.config.ts";
|
||||
|
||||
await start(manifest, config);
|
||||
@@ -0,0 +1,17 @@
|
||||
import { AppProps } from "$fresh/server.ts";
|
||||
|
||||
export default function App({ Component }: AppProps) {
|
||||
return (
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>My Fresh app</title>
|
||||
<link rel="stylesheet" href="/styles.css" />
|
||||
</head>
|
||||
<body>
|
||||
<Component />
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
export default function Page() {
|
||||
return <h1 class="text-red-600 block">foo</h1>;
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"lock": false,
|
||||
"imports": {
|
||||
"$fresh/": "../../",
|
||||
"preact": "https://esm.sh/preact@10.15.1",
|
||||
"preact/": "https://esm.sh/preact@10.15.1/",
|
||||
"tailwindcss": "npm:tailwindcss@3.3.5"
|
||||
},
|
||||
"compilerOptions": {
|
||||
"jsx": "react-jsx",
|
||||
"jsxImportSource": "preact"
|
||||
}
|
||||
}
|
||||
Executable
+6
@@ -0,0 +1,6 @@
|
||||
#!/usr/bin/env -S deno run -A --watch=static/,routes/
|
||||
|
||||
import dev from "$fresh/dev.ts";
|
||||
import config from "./fresh.config.ts";
|
||||
|
||||
await dev(import.meta.url, "./main.ts", config);
|
||||
@@ -0,0 +1,3 @@
|
||||
export function Foo() {
|
||||
return <h1 class="bold text-pp bg-black text-3xl">foo</h1>;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
import { defineConfig } from "$fresh/server.ts";
|
||||
import tailwind from "$fresh/plugins/tailwind.ts";
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [
|
||||
tailwind(),
|
||||
],
|
||||
});
|
||||
@@ -0,0 +1,19 @@
|
||||
// DO NOT EDIT. This file is generated by Fresh.
|
||||
// This file SHOULD be checked into source version control.
|
||||
// This file is automatically updated during development when running `dev.ts`.
|
||||
|
||||
import * as $_app from "./routes/_app.tsx";
|
||||
import * as $index from "./routes/index.tsx";
|
||||
|
||||
import { Manifest } from "$fresh/server.ts";
|
||||
|
||||
const manifest = {
|
||||
routes: {
|
||||
"./routes/_app.tsx": $_app,
|
||||
"./routes/index.tsx": $index,
|
||||
},
|
||||
islands: {},
|
||||
baseUrl: import.meta.url,
|
||||
} satisfies Manifest;
|
||||
|
||||
export default manifest;
|
||||
@@ -0,0 +1,11 @@
|
||||
/// <reference no-default-lib="true" />
|
||||
/// <reference lib="dom" />
|
||||
/// <reference lib="dom.iterable" />
|
||||
/// <reference lib="dom.asynciterable" />
|
||||
/// <reference lib="deno.ns" />
|
||||
|
||||
import { start } from "$fresh/server.ts";
|
||||
import manifest from "./fresh.gen.ts";
|
||||
import config from "./fresh.config.ts";
|
||||
|
||||
await start(manifest, config);
|
||||
@@ -0,0 +1,17 @@
|
||||
import { AppProps } from "$fresh/server.ts";
|
||||
|
||||
export default function App({ Component }: AppProps) {
|
||||
return (
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>My Fresh app</title>
|
||||
<link rel="stylesheet" href="/styles.css" />
|
||||
</head>
|
||||
<body>
|
||||
<Component />
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import { Foo } from "../foo/Foo.tsx";
|
||||
|
||||
export default function Page() {
|
||||
return <Foo />;
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
@@ -0,0 +1,11 @@
|
||||
/** @type {import('tailwindcss').Config} */
|
||||
export default {
|
||||
content: ["./foo/**/*.{ts,tsx}"],
|
||||
theme: {
|
||||
extend: {
|
||||
colors: {
|
||||
pp: "peachpuff",
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,31 @@
|
||||
import { runBuild, withFakeServe } from "$fresh/tests/test_utils.ts";
|
||||
import { assertStringIncludes } from "$std/assert/mod.ts";
|
||||
|
||||
Deno.test("TailwindCSS - dev mode", async () => {
|
||||
await withFakeServe("./tests/fixture_tailwind/dev.ts", async (server) => {
|
||||
const res = await server.get("/styles.css");
|
||||
const content = await res.text();
|
||||
assertStringIncludes(content, ".text-red-600");
|
||||
}, { loadConfig: true });
|
||||
});
|
||||
|
||||
Deno.test("TailwindCSS - build mode", async () => {
|
||||
await runBuild("./tests/fixture_tailwind/dev.ts");
|
||||
await withFakeServe("./tests/fixture_tailwind/main.ts", async (server) => {
|
||||
const res = await server.get("/styles.css");
|
||||
const content = await res.text();
|
||||
assertStringIncludes(content, ".text-red-600");
|
||||
}, { loadConfig: true });
|
||||
});
|
||||
|
||||
Deno.test("TailwindCSS - config", async () => {
|
||||
await withFakeServe(
|
||||
"./tests/fixture_tailwind_config/dev.ts",
|
||||
async (server) => {
|
||||
const res = await server.get("/styles.css");
|
||||
const content = await res.text();
|
||||
assertStringIncludes(content, ".text-pp");
|
||||
},
|
||||
{ loadConfig: true },
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user