Svelte and Tailwind quick project set up
Sep 26, 2024
New Svelte project
pnpm create svelte@latest APPNAME
cd APPNAME
pnpm install
code .
pnpm run dev
Install tailwind
pnpm install -D tailwindcss postcss autoprefixer
npx tailwindcss init -p
Tailwind Setup
Configure template paths
Add the paths to all of your template files in your
tailwind.config.js
file.tailwind.config.js
/** @type {import('tailwindcss').Config} */ export default { content: ['./src/**/*.{html,js,svelte,ts}'], theme: { extend: {} }, plugins: [] };
Add the Tailwind directives to your CSS
Create a
./src/app.css
file and add the@tailwind
directives for each of Tailwind’s layers.app.css
@tailwind base; @tailwind components; @tailwind utilities;
Import the CSS file
Create a
./src/routes/+layout.svelte
file and import the newly-createdapp.css
file.+layout.svelte
<script> import "../app.css"; </script> <slot />