mkdir my-app
cd my-app
npm init svelte@next
npm install -D tailwindcss autoprefixer
Create a postcss.config.cjs file. Svelte 3 is bundled by Vite which comes with postcss support out of the box.
module.exports = {
plugins: {
autoprefixer: {},
tailwindcss: {},
},
}
Create a tailwind.config.cjs file to enable the just-in-time compiler and add the correct paths to be purged. You can also run npx tailwind init
module.exports = {
mode: 'jit',
purge: ['./src/**/*.svelte'],
}
Add these tags somewhere in your css so that postcss knows where to insert the tailwind styles. A good place to import these is the $layout.svelte file.
@tailwind base;
@tailwind components;
@tailwind utilities;