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.jsnpx tailwindcss init -
Amend the content array in the
tailwind.config.jsas followsmodule.exports = { content: [ './src/Client/**/*.html', './src/Client/**/*.fs', ], theme: { extend: {}, }, plugins: [], } -
Create a
postcss.config.jswith the followingmodule.exports = { plugins: { tailwindcss: {}, autoprefixer: {}, } } -
Add the Tailwind layers to your
style.css@tailwind base; @tailwind components; @tailwind utilities; -
Find the
module.rulesfield in thewebpack.config.jsand in the css files rule’susefield 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/Clientfolder find the code inIndex.fsto 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