Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Elian Van Cutsem
Elian Van Cutsem

Posted on • Originally published atelian.codes on

     

Use TailwindCSS with Sveltekit (2021)

Since my previous blogpost on usingTailwindCSS (JIT) withSveltekit, a lot has changed. That's why I've updated the article to a newer (and better) method.

Setting up Sveltekit

Setting up a new Sveltekit project is not that hard anymore. Just run the following set of commands:

npm init svelte@next tailwind-sveltekit-app
Enter fullscreen modeExit fullscreen mode

You can always searchthe official documentation for more info

Adding an adapter

In most cases, I tend to use Sveltekit as a static site generator. To tell Sveltekit to create static pages, add the static-adapter with following command:

npm i @sveltejs/adapter-static@next
Enter fullscreen modeExit fullscreen mode

Also add the following to thesvelte.config.cjs

constadapter=require('@sveltejs/adapter-static');module.exports={kit:{adapter:adapter({pages:'build',assets:'build',fallback:null})}};
Enter fullscreen modeExit fullscreen mode

This tells Sveltekit to put the output in thebuild folder and dont use a fallback (so generate aindex.html,404.html,contact.html, ...)

more info on the adapterhere

Adding TailwindCSS

Previously I described some additional steps to install Tailwind, like installing autoprefixer and PostCSS. I also setup some extra NPM scripts.

Since TailwindCSS is used a lot across the web these days, it got way easier. Just use the following command:

npx svelte-add@latest tailwindcss
Enter fullscreen modeExit fullscreen mode

This will install TailwindCSS, PostCSS and other dependencies. It will also add the configuration and a basicapp.css file with Tailwind imported.

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Core Astro Team | devs.gent meetup organizer | BeJS, React Brussels & React Paris household figure | public speaker | Podcast Host
  • Location
    Ghent, Belgium
  • Education
    Bachelors in ICT, specialisation in Web & Mobile development
  • Work
    Core Astro Team at The Astro Technology Company
  • Joined

More fromElian Van Cutsem

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp