SvelteKit with TailwindCSS and JIT

by webmaster 2021-04-12 #svelte #tailwind
SvelteKit with TailwindCSS and JIT

Svelte is my all-time favorite JS framework. Fresh on its heels comes SvelteKit, a framework for generating static sites with Svelte. Just what the doctor ordered.

SvelteKit is currently in public beta, but it's caused a lot of chatter over the interwebs, and that made me give it a spin.

Here's a super simple setup to scaffold a SvelteKit static site. Since I also ❤️ TailwindCSS, I have instructions for that as well. And to make it a complete package, it all runs on Vite, for a super fast ⚡️ development environment.

Check out my newer Svelte, Vite, TailwindCSS 3 article if all you need is the base Svelte framework.

# 1. Create a new Svelte Kit site
# My choices: no TypeScript, ESLint, Prettier
npm init svelte@next my-app

cd my-app

# 2. Install packages
npm install

# 3. Add TailwindCSS
# @see https://github.com/svelte-add/tailwindcss
npx svelte-add@latest tailwindcss

Step 3 automates most of Tailwind's configuration, by creating pre-populated configs for postcss.config.cjs, tailwind.config.cjs, and filling in the required PostCSS config in svelte.config.cjs.

To finalize installing Tailwind, open app.css and add the base Tailwind styles right at the top:

@tailwind base;

// Custom CSS goes here

@tailwind components;
@tailwind utilities;
...

Finally start it in dev mode, and open it in the browser.

# Run in development mode, and open the site in the browser
npm run dev -- --open
Liked this article? Share it on your favorite platform.