Hi friends. I've decided to share my setup process for a perfect project with Svelte & Tailwind. Maybe some of you will find it useful. For those who are not familiar, the Svelte and Tailwind are a perfect match for quick and enjoyable web development. However, before, we had to manually configure everything in Rollup. Not anymore, with just a couple of simple commands, you get, IMHO, the best UX ever. Tailwind has just come out with JIT (just in time compiler) that makes it very quick. Add to this the new SvelteKit and Vite and you have an enjoyable web-dev process! Here are the commands:
- We create a new folder and change the working directory to it
mkdir my-app
cd my-app
- Initialize a new SvleteKit project in the folder
npm init svelte@next
- Add the static adapter so we can build and export static files
npm i -D @sveltejs/adapter-static
- Add Tailwind with JIT
npx svelte-add tailwindcss --jit
- Install all the dependencies
npm i
- Run the development server
npm run dev
One thing to notice that in order to build static files we will need to modify a bit the svelte.config.cjs file in the root folder of the project.
Instead of
const node = require('@sveltejs/adapter-node');
We need to import this
const static = require('@sveltejs/adapter-static');
and also instead of the default node adapter
adapter: node(),
we will need to add the static adapter like this
adapter: {
adapt: static
},
After
npm run build
in build folder, you'll find the files that could be uploaded to your CDN of choice for free hosting, like Vercel, Surge or Cloudflare. I hope it helps, my friends! Happy development!
Top comments (4)
Hi, thanks for the combo guidelines!
I have followed the steps above and in my case, I need to do two more steps.
svelte.config.js
, import/require the tailwind & autoprefixer and add it to the postcssI've made a boilerplate so I can refer it and reuse when needed. Hope it helps.
github.com/chenxeed/svelte-tailwin...
One more step before
npx svelte-add tailwindcss --jit
is
npm install -D @tailwindcss/jit tailwindcss postcss
Nice article. Thanks
Not true. You are supposed to install dependencies after the command runs with
npm install
orpnpm install
oryarn
.Fixed that. Thanks