How do I add Tailwind to a SAFE project?
Tailwind is a utility-first CSS framework packed that can be composed to build any design, directly in your markup.
-
Add a stylesheet to the project
-
Install the required npm packages
npm install -D tailwindcss postcss autoprefixer postcss-loader
- Initialise a
tailwind.config.js
npx tailwindcss init
-
Amend the content array in the
tailwind.config.js
as followsmodule.exports = { content: [ './src/Client/**/*.html', './src/Client/**/*.fs', ], theme: { extend: {}, }, plugins: [], }
-
Create a
postcss.config.js
with the followingmodule.exports = { plugins: { tailwindcss: {}, autoprefixer: {}, } }
-
Add the Tailwind layers to your
style.css
@tailwind base; @tailwind components; @tailwind utilities;
-
Find the
module.rules
field in thewebpack.config.js
and in the css files rule’suse
field addpostcss-loader
{ test: /\.(sass|scss|css)$/, use: [ isProduction ? MiniCssExtractPlugin.loader : 'style-loader', 'css-loader', { loader: 'sass-loader', options: { implementation: require('sass') } }, 'postcss-loader' ], },
-
In the
src/Client
folder find the code inIndex.fs
to show the list of todos and add a Tailwind text colour class(text-red-200)for todo in model.Todos do Html.li [ prop.classes [ "text-red-200" ] prop.text todo.Description ]
You should see some nice red todos proving that Tailwind is now in your project