Skip to content

Commit

Permalink
feat: move tailwind plugin into its own folder
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinhagemeister committed Mar 27, 2024
1 parent c8304ab commit 6c23ef4
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 21 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 11 additions & 7 deletions deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,12 @@
"$std/": "https://deno.land/[email protected]/",
"@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/[email protected]",
"preact/": "https://esm.sh/[email protected]/",
"preact-render-to-string": "https://esm.sh/[email protected]?external=preact",
"@preact/signals": "https://esm.sh/@preact/[email protected]?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",
Expand All @@ -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:[email protected]",
"esbuild-wasm": "npm:[email protected]",
"preact": "https://esm.sh/[email protected]",
"preact-render-to-string": "https://esm.sh/[email protected]?external=preact",
"preact/": "https://esm.sh/[email protected]/",
"tailwindcss": "npm:tailwindcss@^3.4.1",
"tailwindcss/plugin": "npm:/tailwindcss@^3.4.1/plugin.js",
"esbuild-wasm": "npm:[email protected]",
"esbuild": "npm:[email protected]",
"twind": "https://esm.sh/[email protected]",
"twind/": "https://esm.sh/[email protected]/"
"twind/": "https://esm.sh/[email protected]/",
"postcss": "npm:[email protected]",
"cssnano": "npm:[email protected]",
"autoprefixer": "npm:[email protected]"
},
"compilerOptions": {
"jsx": "react-jsx",
Expand Down
10 changes: 8 additions & 2 deletions init/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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<string, string>,
compilerOptions: {
jsx: "react-jsx",
jsxImportSource: "preact",
},
};

if (useTailwind) {
denoJson.imports["tailwindcss"] = "npm:[email protected]";
denoJson.imports["tailwindcss/plugin"] = "npm:[email protected]/plugin.js";
}

await writeProjectFile("deno.json", denoJson);

const README_MD = `# Fresh project
Expand Down
15 changes: 15 additions & 0 deletions plugin-tailwindcss/deno.json
Original file line number Diff line number Diff line change
@@ -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:[email protected]",
"cssnano": "npm:[email protected]",
"postcss": "npm:[email protected]",
"tailwindcss": "npm:tailwindcss@^3.4.1"
}
}
Original file line number Diff line number Diff line change
@@ -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"];

Expand Down
11 changes: 4 additions & 7 deletions src/plugins/tailwind/mod.ts → plugin-tailwindcss/src/mod.ts
Original file line number Diff line number Diff line change
@@ -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:[email protected]";
import { DevApp } from "@fresh/core/dev";

export function tailwind<T>(
app: DevApp<T>,
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,
});

Expand Down
File renamed without changes.
5 changes: 4 additions & 1 deletion www/deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@
"@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",
"@std/media-types": "jsr:@std/media-types@^0.220.1",
"@std/fmt": "jsr:@std/fmt",
"@std/fs": "jsr:@std/fs",
"@std/jsonc": "jsr:@std/jsonc@^0.220.1",
"autoprefixer": "npm:[email protected]",
"cssnano": "npm:[email protected]",
"postcss": "npm:[email protected]",
"@luca/esbuild-deno-loader": "jsr:@luca/esbuild-deno-loader@^0.10.3",
"preact": "https://esm.sh/[email protected]",
"preact/": "https://esm.sh/[email protected]/",
Expand Down

0 comments on commit 6c23ef4

Please sign in to comment.