feat: support tailwindcss v4 (#3054)

update /www and tailwind-plugin to support tailwind v4.

Thanks to the merge of #3034, the work of integrating and advancing
#2903 is promoted.

related #3034 
related #2903 

close #3056
close #2819

--patch-1 
based on review,

1. del compiler and make it more clean and simple,
2.  fix init tailwind part,
3. fix test tailwind part

--patch-2

1. fix the docs 
2. fix the docs of plugin and version

--patch-3
1. Addressed various maintenance tasks (chores)
2. Updated the Tailwind CSS plugin to align with this release. Generated
a fresh project using the updated init configuration and
3. deployed it via Deno Deploy EA. Deployment is functioning correctly.

--patch-4
Move postcss imports to Tailwind section in init script

--patch-5
Refactored Tailwind plugin type definitions by copying PluginOptions
properties from @tailwindcss/postcss and adding Fresh-specific exclude
option, while exporting types from package entrypoint for better
accessibility.

Test Project: https://fresh.fresh-press.deno.net/
Test Project Repository:
https://github.com/SisyphusZheng/fresh-tailwindv4
Test Plugin: https://jsr.io/@freshpress/fresh-plugin-tailwind@1.0.0

---------

Co-authored-by: 李嘉图·M·路 <146103794+Ricardo-M-Zheng@users.noreply.github.com>
Co-authored-by: Asher Gomez <ashersaupingomez@gmail.com>
Co-authored-by: Marvin Hagemeister <marvin@deno.com>
This commit is contained in:
Zhi
2025-07-21 16:13:34 +02:00
committed by GitHub
co-authored by 李嘉图·M·路 Asher Gomez Marvin Hagemeister
parent 2d308f6b9e
commit bb23643779
30 changed files with 741 additions and 1144 deletions
+13 -9
View File
@@ -4,9 +4,12 @@ import * as path from "@std/path";
// Keep these as is, as we replace these version in our release script
const FRESH_VERSION = "2.0.0-alpha.43";
const FRESH_TAILWIND_VERSION = "0.0.1-alpha.7";
const FRESH_TAILWIND_VERSION = "0.0.1-alpha.8";
const PREACT_VERSION = "10.26.9";
const PREACT_SIGNALS_VERSION = "2.2.1";
const TAILWINDCSS_VERSION = "4.1.10";
const TAILWINDCSS_POSTCSS_VERSION = "4.1.10";
const POSTCSS_VERSION = "8.5.6";
function css(strs: TemplateStringsArray, ...exprs: string[]): string {
let out = "";
@@ -309,7 +312,7 @@ html {
.border-2 {
border-width: 2px;
}
.rounded {
.rounded-sm {
border-radius: 0.25rem;
}
.hover\\:bg-gray-200:hover {
@@ -320,11 +323,8 @@ html {
}
${GRADIENT_CSS}`;
// deno-fmt-ignore
const TAILWIND_CSS = css`@tailwind base;
@tailwind components;
@tailwind utilities;
const TAILWIND_CSS = css`@import "tailwindcss";
${GRADIENT_CSS}`;
const cssStyles = useTailwind ? TAILWIND_CSS : NO_TAILWIND_STYLES;
@@ -405,7 +405,7 @@ export function Button(props: ButtonProps) {
return (
<button
{...props}
class="px-2 py-1 border-gray-500 border-2 rounded bg-white hover:bg-gray-200 transition-colors"
class="px-2 py-1 border-gray-500 border-2 rounded-sm bg-white hover:bg-gray-200 transition-colors"
/>
);
}`;
@@ -503,7 +503,7 @@ import { Builder } from "fresh/dev";
import { app } from "./main.ts";
const builder = new Builder();
${useTailwind ? "tailwind(builder, app, {});" : ""}
${useTailwind ? "tailwind(builder, app);" : ""}
if (Deno.args.includes("build")) {
await builder.build(app);
} else {
@@ -512,6 +512,7 @@ if (Deno.args.includes("build")) {
await writeFile("dev.ts", DEV_TS);
const denoJson = {
nodeModulesDir: "auto",
tasks: {
check: "deno fmt --check . && deno lint . && deno check",
dev: "deno run -A --watch=static/,routes/ dev.ts",
@@ -546,9 +547,12 @@ if (Deno.args.includes("build")) {
};
if (useTailwind) {
denoJson.imports["tailwindcss"] = "npm:tailwindcss@^3.4.3";
denoJson.imports["tailwindcss"] = `npm:tailwindcss@^${TAILWINDCSS_VERSION}`;
denoJson.imports["@fresh/plugin-tailwind"] =
`jsr:@fresh/plugin-tailwind@^${FRESH_TAILWIND_VERSION}`;
denoJson.imports["@tailwindcss/postcss"] =
`npm:@tailwindcss/postcss@^${TAILWINDCSS_POSTCSS_VERSION}`;
denoJson.imports["postcss"] = `npm:postcss@^${POSTCSS_VERSION}`;
}
await writeFile("deno.json", denoJson);
+1 -1
View File
@@ -92,7 +92,7 @@ Deno.test("init - with tailwind", async () => {
await initProject(dir, [], {});
const css = await readProjectFile(dir, "static/styles.css");
expect(css).toMatch(/@tailwind/);
expect(css).toMatch(/@import "tailwindcss"/);
const main = await readProjectFile(dir, "main.ts");
const dev = await readProjectFile(dir, "dev.ts");