Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Tailwindcss plugin. Close #344
- Loading branch information
1 parent
aedc01a
commit ae17fa0
Showing
10 changed files
with
2,027 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { default } from "npm:@lumeland/tailwindcss@3.2.5"; | ||
export type { Config } from "npm:@lumeland/tailwindcss@3.2.5"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import tailwind, { Config } from "../deps/tailwindcss.ts"; | ||
import { merge } from "../core/utils.ts"; | ||
|
||
import type { Site } from "../core.ts"; | ||
|
||
export interface Options { | ||
extensions: string[]; | ||
options: Config; | ||
} | ||
|
||
export const defaults: Options = { | ||
extensions: [".html"], | ||
options: {}, | ||
}; | ||
|
||
export default function (userOptions?: Partial<Options>) { | ||
const options = merge(defaults, userOptions); | ||
|
||
return (site: Site) => { | ||
// deno-lint-ignore no-explicit-any | ||
let tailwindPlugins: any[]; | ||
|
||
if (site.hooks.postcss) { | ||
throw new Error( | ||
"PostCSS plugin is required to be installed AFTER TailwindCSS plugin", | ||
); | ||
} | ||
|
||
site.processAll(options.extensions, (pages) => { | ||
// Get the content of all HTML pages | ||
const content = pages.map((page) => ({ raw: page.content as string })); | ||
|
||
// Create Tailwind plugin | ||
// @ts-ignore: This expression is not callable. | ||
const plugin = tailwind({ | ||
...options.options, | ||
content, | ||
}); | ||
|
||
// Ensure PostCSS plugin is installed | ||
if (!site.hooks.postcss) { | ||
throw new Error( | ||
"PostCSS plugin is required to be installed AFTER TailwindCSS plugin", | ||
); | ||
} | ||
|
||
// Replace the old Tailwind plugin configuration from PostCSS plugins | ||
// deno-lint-ignore no-explicit-any | ||
site.hooks.postcss((runner: any) => { | ||
tailwindPlugins?.forEach((plugin) => { | ||
runner.plugins.splice(runner.plugins.indexOf(plugin), 1); | ||
}); | ||
tailwindPlugins = runner.normalize([plugin]); | ||
runner.plugins = runner.plugins.concat(tailwindPlugins); | ||
}); | ||
}); | ||
}; | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
menuButton.addEventListener("click", function () { | ||
const classList = document.getElementById("nav").classList; | ||
classList.toggle("gap-8"); | ||
classList.toggle("gap-16"); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
@tailwind base; | ||
@tailwind components; | ||
@tailwind utilities; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { assertSiteSnapshot, build, getSite } from "./utils.ts"; | ||
import postcss from "../plugins/postcss.ts"; | ||
import tailwindcss from "../plugins/tailwindcss.ts"; | ||
|
||
Deno.test("postcss plugin", async (t) => { | ||
const site = getSite({ | ||
src: "tailwindcss", | ||
}); | ||
|
||
site.use(tailwindcss({ | ||
extensions: [".html", ".js"], | ||
})); | ||
site.use(postcss()); | ||
site.loadAssets([".js"]); | ||
|
||
await build(site); | ||
await assertSiteSnapshot(t, site); | ||
}); |