CSS Frameworks
Tailwindโ
To enable support for Tailwind in your project, you need to add two config files โ tailwind.config.cjs and postcss.config.cjs โ to the root directory.
With these files present, Wasp installs the necessary dependencies and copies your configuration to the generated project. You can then use Tailwind CSS directives in your CSS and Tailwind classes on your React components.
.
โโโ main.wasp
โโโ src
โย ย โโโ client
โย ย โย ย โโโ tsconfig.json
โย ย โย ย โโโ Main.css
โย ย โย ย โโโ MainPage.js
โย ย โย ย โโโ waspLogo.png
โย ย โโโ server
โย ย โย ย โโโ tsconfig.json
โย ย โโโ shared
โย ย โโโ tsconfig.json
โโโ postcss.config.cjs
โโโ tailwind.config.cjs
If you can not use Tailwind after adding the required config files, make sure to restart wasp start. This is sometimes needed to ensure that Wasp picks up the changes and enables Tailwind integration.
Enabling Tailwind Step-by-Stepโ
Make sure to use the .cjs extension for these config files, if you name them with a .js extension, Wasp will not detect them.
- Add
./tailwind.config.cjs.
/** @type {import('tailwindcss').Config} */
module.exports = {
content: [ "./src/**/*.{js,jsx,ts,tsx}" ],
theme: {
extend: {},
},
plugins: [],
}
- Add
./postcss.config.cjs.
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
}
- Import Tailwind into your CSS file. For example, in a new project you might import Tailwind into
Main.css.
@tailwind base;
@tailwind components;
@tailwind utilities;
/* ... */
- Start using Tailwind ๐ฅณ
// ...
<h1 className="text-3xl font-bold underline">
Hello world!
</h1>
// ...
Adding Tailwind Pluginsโ
To add Tailwind plugins, add it to dependencies in your main.wasp file and to the plugins list in your tailwind.config.cjs file:
app todoApp {
// ...
dependencies: [
("@tailwindcss/forms", "^0.5.3"),
("@tailwindcss/typography", "^0.5.7"),
],
// ...
}
/** @type {import('tailwindcss').Config} */
module.exports = {
// ...
plugins: [
require('@tailwindcss/forms'),
require('@tailwindcss/typography'),
],
// ...
}