From 83925cc1e35703bdc7d40462224fafa448f4dcdc Mon Sep 17 00:00:00 2001 From: Lino Le Van <11367844+lino-levan@users.noreply.github.com> Date: Sat, 17 Jun 2023 10:16:12 -0700 Subject: [PATCH] docs(examples): Using twind v1 + fix md code syntax highlighting (#1271) Co-authored-by: Luca Casonato --- docs/examples/setting-the-language.md | 4 +- docs/examples/using-twind-v1.md | 62 +++++++++++++++++++++++++++ docs/toc.json | 1 + 3 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 docs/examples/using-twind-v1.md diff --git a/docs/examples/setting-the-language.md b/docs/examples/setting-the-language.md index cb091012..645ec49e 100644 --- a/docs/examples/setting-the-language.md +++ b/docs/examples/setting-the-language.md @@ -6,7 +6,7 @@ description: | When you initialize a project with `deno run -A -r https://fresh.deno.dev`, you'll end up with a `main.ts` like the following: -``` +```ts /// /// /// @@ -26,7 +26,7 @@ This is a great start if your site is in English, but let's say you want to change the language, as per the `` tag. Then you'll need to do something like this: -``` +```ts /// /// /// diff --git a/docs/examples/using-twind-v1.md b/docs/examples/using-twind-v1.md new file mode 100644 index 00000000..fa865e09 --- /dev/null +++ b/docs/examples/using-twind-v1.md @@ -0,0 +1,62 @@ +--- +description: | + With a few tweaks one can use twind v1 +--- + +When you initialize a project with `deno run -A -r https://fresh.deno.dev`, +you'll end up with a `main.ts` like the following: + +```ts +/// +/// +/// +/// +/// + +import { start } from "$fresh/server.ts"; +import manifest from "./fresh.gen.ts"; + +import twindPlugin from "$fresh/plugins/twind.ts"; +import twindConfig from "./twind.config.ts"; + +await start(manifest, { plugins: [twindPlugin(twindConfig)] }); +``` + +The template generates a Twind v0 project by default. If you want to use Twind +v1 you can follow this guide. First of all, change the import path to use the +`twindv1` plugin: + +```ts +/// +/// +/// +/// +/// + +import { start } from "$fresh/server.ts"; +import manifest from "./fresh.gen.ts"; + +import twindPlugin from "$fresh/plugins/twindv1.ts"; +import twindConfig from "./twind.config.ts"; + +await start(manifest, { plugins: [twindPlugin(twindConfig)] }); +``` + +The twind config object has changed significantly in v1, so we must also go +change `twind.config.ts`. A good base looks like this: + +```ts +import { defineConfig } from "https://esm.sh/@twind/core@1.1.3"; +import presetTailwind from "https://esm.sh/@twind/preset-tailwind@1.1.4"; +import presetAutoprefix from "https://esm.sh/@twind/preset-autoprefix@1.0.7"; + +export default { + ...defineConfig({ + presets: [presetTailwind(), presetAutoprefix()], + }), + selfURL: import.meta.url, +}; +``` + +To see what other presets exist, you can go to the +[twind docs](https://twind.style/presets). diff --git a/docs/toc.json b/docs/toc.json index 5e0f8363..a309af9d 100644 --- a/docs/toc.json +++ b/docs/toc.json @@ -45,6 +45,7 @@ ["setting-the-language", "Setting the language"], ["writing-tests", "Writing tests"], ["changing-the-src-dir", "Changing the source directory"], + ["using-twind-v1", "Using Twind v1"], ["init-the-server", "Initializing the server"], ["using-fresh-canary-version", "Using Fresh canary version"] ]