The content is a brief repository demonstration that explains how to integrate Tailwind CSS into the Svelte pipeline without the need for additional scripts. It highlights the idea of leveraging the postcss plugins used by Tailwind, instead of relying on the Tailwind CLI. The demonstration includes steps to add the necessary dependencies, configure the rollup file, and import Tailwind using a global style block.
To install the Tailwind/Svelte integration, follow these steps:
Add the necessary dependencies using the following command:
yarn add -D tailwindcss autoprefixer svelte-preprocess
Set up the rollup.config.js file by adding the following blocks:
// ...existing code
import sveltePreprocess from 'svelte-preprocess';
import postcss from 'rollup-plugin-postcss';
// ...existing code
plugins: [
// ...existing plugins
postcss({
plugins: [
require('tailwindcss'),
require('autoprefixer'),
],
}),
],
// ...existing code
Configure the svelte rollup plugin to include preprocess. Add the following line to the svelte() section of the rollup.config.js file:
preprocess: sveltePreprocess(),
Add a <style global> block to the desired Svelte component. For example, add the following block to the src/App.svelte component:
<style global>
@import 'tailwindcss/base';
@import 'tailwindcss/components';
@import 'tailwindcss/utilities';
</style>
Important: In an actual app, it is recommended to place the global style block in a file that will not change. This is because the initial build process for Tailwind can be slow, going through the entire 3mb+ worth of Tailwind CSS. Placing the block in an unchanged file allows for faster incremental builds.
You’re done! The Tailwind CSS integration should now be in place.
The content provides a demonstration of integrating Tailwind CSS into the Svelte pipeline without additional scripts. Instead of relying on the Tailwind CLI, the integration leverages the postcss plugins used by Tailwind directly. The steps include adding dependencies, configuring the rollup.config.js file, and adding a global style block to import Tailwind. The article emphasizes the ease and efficiency of the integration process while also suggesting optimization tricks for faster builds during development.