๐ TailwindCSS 2.x with Snowpack Setup
๐ Subscribe to My Channel ๐โค๏ธYoutubeโค๏ธ๐
The setup was slow when I used the tailwind directives like @apply inside the CSS files
List of packages installed
Package Name | Version |
---|---|
@snowpack/plugin-postcss | ^1.1.0 |
@tailwindcss/postcss7-compat | ^2.0.2 |
autoprefixer | ^10.2.3 |
postcss | ^8.2.4 |
postcss-cli | ^8.3.1 |
snowpack | ^3.0.11 |
tailwindcss | ^2.0.2 |
๐ Clone this repo
- Install Packages
npm install
- To run the dev server
npm run start
- To run the prod build
npm run build
Steps to Follow
-
open the folder(your project folder) and run
npm init -y
to create
package.json
with default settings. -
Install Snowpack using
npm i snowpack -D
-
add these scripts to your
package.json
"scripts": { "start": "snowpack dev", "build": "snowpack build" },
start
- to run the local development server.build
- to create a production build -
Let's install TailwindCSS 2.x
npm install tailwindcss@latest postcss@latest autoprefixer@latest -D
-
next we need to create
tailwind.config.js
andpostcss.config.js
. To generate these files runnpx tailwindcss init -p
-
add
tailwindcss
andautoprefixer
to the postcss plugins insidepostcss.config.js
module.exports = { plugins: [require("tailwindcss"), require("autoprefixer")], };
-
next we need to instruct snowpack to run postcss. Install snowpack postcss plugin
npm install @snowpack/plugin-postcss postcss postcss-cli -D
-
next we need to create
snowpack.config.js
in the root of the project directory and add the following codemodule.exports = { plugins: ["@snowpack/plugin-postcss"], };
- create these files inside the root of the project directory
index.html
index.css
index.js
@tailwind base;
@tailwind components;
@tailwind utilities;
-
Add
index.css
toindex.html
using<link rel="stylesheet" href="index.css" />
- Add
purge
rule totailwind.config.js
module.exports = {
purge: ["./**/*.html"],
darkMode: false, // or 'media' or 'class'
theme: {
extend: {},
},
variants: {
extend: {},
},
plugins: [],
};
and run
npm run build
which creates a build folder.
Made with โค๏ธ - by FrontEndFunn