diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 7b4f5e62eac..817867f719a 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -27,4 +27,8 @@ jobs: - name: Publish @fresh/init working-directory: ./init + run: deno publish --allow-dirty + + - name: Publish @fresh/plugin-tailwindcss + working-directory: ./plugin-tailwindcss run: deno publish --allow-dirty \ No newline at end of file diff --git a/deno.json b/deno.json index 65959103218..0fc71de19a5 100644 --- a/deno.json +++ b/deno.json @@ -40,14 +40,12 @@ "$std/": "https://deno.land/std@0.216.0/", "@fresh/core": "./src/mod.ts", "@fresh/core/dev": "./src/dev/mod.ts", - "@fresh/plugin-tailwind": "./src/plugins/tailwind/mod.ts", + "@fresh/plugin-tailwind": "./plugin-tailwindcss/src/mod.ts", "@fresh/runtime": "./src/runtime/mod.ts", "@fresh/server": "./src/mod.ts", "@luca/esbuild-deno-loader": "jsr:@luca/esbuild-deno-loader@^0.10.3", - "preact": "https://esm.sh/preact@10.20.1", - "preact/": "https://esm.sh/preact@10.20.1/", - "preact-render-to-string": "https://esm.sh/preact-render-to-string@6.4.1?external=preact", "@preact/signals": "https://esm.sh/@preact/signals@1.2.3?external=preact", + "@std/cli": "jsr:@std/cli@^0.220.1", "@std/crypto": "jsr:@std/crypto@^0.220.1", "@std/encoding": "jsr:@std/encoding@^0.220.1", "@std/expect": "jsr:@std/expect@^0.220.1", @@ -56,12 +54,18 @@ "@std/jsonc": "jsr:@std/jsonc@^0.220.1", "@std/media-types": "jsr:@std/media-types@^0.220.1", "@std/path": "jsr:@std/path@^0.220.1", + "esbuild": "npm:esbuild@0.20.2", + "esbuild-wasm": "npm:esbuild-wasm@0.20.2", + "preact": "https://esm.sh/preact@10.20.1", + "preact-render-to-string": "https://esm.sh/preact-render-to-string@6.4.1?external=preact", + "preact/": "https://esm.sh/preact@10.20.1/", "tailwindcss": "npm:tailwindcss@^3.4.1", "tailwindcss/plugin": "npm:/tailwindcss@^3.4.1/plugin.js", - "esbuild-wasm": "npm:esbuild-wasm@0.20.2", - "esbuild": "npm:esbuild@0.20.2", "twind": "https://esm.sh/twind@0.16.19", - "twind/": "https://esm.sh/twind@0.16.19/" + "twind/": "https://esm.sh/twind@0.16.19/", + "postcss": "npm:postcss@8.4.35", + "cssnano": "npm:cssnano@6.0.3", + "autoprefixer": "npm:autoprefixer@10.4.17" }, "compilerOptions": { "jsx": "react-jsx", diff --git a/init/mod.ts b/init/mod.ts index fa29116da46..9dbc0cc0390 100644 --- a/init/mod.ts +++ b/init/mod.ts @@ -364,7 +364,7 @@ if (import.meta.main) { await writeProjectFile("main.ts", MAIN_TS); const DEV_TS = `#!/usr/bin/env -S deno run -A --watch=static/,routes/ -import { tailwind } from "@fresh/plugin-tailwind"; +${useTailwind ? `import { tailwind } from "@fresh/plugin-tailwind";\n` : ""}; import { FreshDevApp } from "@fresh/core/dev"; import { app } from "./main.ts"; @@ -398,15 +398,21 @@ const denoJson = { imports: { // FIXME: Update once relased "@fresh/core": "jsr:@marvinh-test/fresh@^2.0.0-prealpha.8", + "@fresh/plugin-tailwind": "jsr:@marvinh-test/fresh@^2.0.0-prealpha.8", "preact": "npm:preact@^10.20.1", "preact/signals": "npm:preact@^1.2.3", - }, + } as Record, compilerOptions: { jsx: "react-jsx", jsxImportSource: "preact", }, }; +if (useTailwind) { + denoJson.imports["tailwindcss"] = "npm:tailwindcss@3.4.1"; + denoJson.imports["tailwindcss/plugin"] = "npm:tailwindcss@3.4.1/plugin.js"; +} + await writeProjectFile("deno.json", denoJson); const README_MD = `# Fresh project diff --git a/plugin-tailwindcss/deno.json b/plugin-tailwindcss/deno.json new file mode 100644 index 00000000000..078905af964 --- /dev/null +++ b/plugin-tailwindcss/deno.json @@ -0,0 +1,15 @@ +{ + "name": "@marvinh-test/fresh-tailwind", + "version": "0.0.1", + "exports": { + ".": "./src/mod.ts" + }, + "imports": { + "@fresh/core": "jsr:@marvinh-test/fresh@^2.0.0-prealpha.0", + "@std/path": "jsr:@std/path@^0.220.1", + "autoprefixer": "npm:autoprefixer@10.4.17", + "cssnano": "npm:cssnano@6.0.3", + "postcss": "npm:postcss@8.4.35", + "tailwindcss": "npm:tailwindcss@^3.4.1" + } +} diff --git a/src/plugins/tailwind/compiler.ts b/plugin-tailwindcss/src/compiler.ts similarity index 91% rename from src/plugins/tailwind/compiler.ts rename to plugin-tailwindcss/src/compiler.ts index b49d4c26ec0..4318b8c70af 100644 --- a/src/plugins/tailwind/compiler.ts +++ b/plugin-tailwindcss/src/compiler.ts @@ -1,10 +1,10 @@ import tailwindCss, { Config } from "tailwindcss"; -import postcss from "npm:postcss@8.4.35"; -import cssnano from "npm:cssnano@6.0.3"; -import autoprefixer from "npm:autoprefixer@10.4.17"; +import postcss from "postcss"; +import cssnano from "cssnano"; +import autoprefixer from "autoprefixer"; import * as path from "@std/path"; import { TailwindPluginOptions } from "./types.ts"; -import { ResolvedFreshConfig } from "../../config.ts"; +import { ResolvedFreshConfig } from "@fresh/core"; const CONFIG_EXTENSIONS = ["ts", "js", "mjs"]; diff --git a/src/plugins/tailwind/mod.ts b/plugin-tailwindcss/src/mod.ts similarity index 57% rename from src/plugins/tailwind/mod.ts rename to plugin-tailwindcss/src/mod.ts index 72cd47a2a3c..bedeecd71b0 100644 --- a/src/plugins/tailwind/mod.ts +++ b/plugin-tailwindcss/src/mod.ts @@ -1,19 +1,16 @@ import { TailwindPluginOptions } from "./types.ts"; import { initTailwind } from "./compiler.ts"; -import { DevApp } from "../../dev/dev_app.ts"; -import { Processor } from "npm:postcss@8.4.35"; +import { DevApp } from "@fresh/core/dev"; export function tailwind( app: DevApp, options: TailwindPluginOptions = {}, ): void { - let processor: Processor | null = null; + const processor = initTailwind(app.config, options); app.onTransformStaticFile({ filter: /\.css$/ }, async (args) => { - if (processor === null) { - processor = await initTailwind(app.config, options); - } - const res = await processor.process(args.text, { + const instance = await processor; + const res = await instance.process(args.text, { from: args.path, }); diff --git a/src/plugins/tailwind/types.ts b/plugin-tailwindcss/src/types.ts similarity index 100% rename from src/plugins/tailwind/types.ts rename to plugin-tailwindcss/src/types.ts diff --git a/www/deno.json b/www/deno.json index 5d0c66924aa..720924524c4 100644 --- a/www/deno.json +++ b/www/deno.json @@ -12,7 +12,7 @@ "@fresh/core/dev": "../src/dev/mod.ts", "@fresh/server": "../src/mod.ts", "@fresh/runtime": "../src/runtime/client/mod.tsx", - "@fresh/plugin-tailwind": "../src/plugins/tailwind/mod.ts", + "@fresh/plugin-tailwind": "../plugin-tailwindcss/src/mod.ts", "@std/crypto": "jsr:@std/crypto", "@std/path": "jsr:@std/path", "@std/encoding": "jsr:@std/encoding", @@ -20,6 +20,9 @@ "@std/fmt": "jsr:@std/fmt", "@std/fs": "jsr:@std/fs", "@std/jsonc": "jsr:@std/jsonc@^0.220.1", + "autoprefixer": "npm:autoprefixer@10.4.17", + "cssnano": "npm:cssnano@6.0.3", + "postcss": "npm:postcss@8.4.35", "@luca/esbuild-deno-loader": "jsr:@luca/esbuild-deno-loader@^0.10.3", "preact": "https://esm.sh/preact@10.20.1", "preact/": "https://esm.sh/preact@10.20.1/",