DEV Community

Cover image for Tailwind CSS installation and development environment
Teresa Carbajal
Teresa Carbajal

Posted on • Updated on

Tailwind CSS installation and development environment

Hello Devs! πŸ™‚

In this blog, we will see how to make our installation and development environment. ☝️

Don't worry! I will guide you and together, we will learn, ok!

1:

Open: We need to open our terminal and there open our folder.

In this case, create a folder with:

  • mkdir "named for you"

We can see the documents that we need to see:

  • ls

To enter with:

  • cd "name folder"

πŸ‘‡

In terminal

tailwind_test % mkdir tailwind_test
tailwind_test % ls
 tailwind_test
tailwind_test % cd tailwind_test
Enter fullscreen mode Exit fullscreen mode

2:

Initialize project: we can initialize the project with npm.

πŸ‘‡

In terminal

tailwind_test % npm init -y
Wrote to /Users/Tere/Documents/project/package.json:

{
  "name": "project",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}
Enter fullscreen mode Exit fullscreen mode

3:

Install Tailwind via npm: In this case we make by npm. Also, in this case, We will install another way.

If you want to see, You'll be able to see it below in the second example in the terminal.

First example:

πŸ‘‡πŸ›‘ Remember in this case we make the second example, but also you can do it this way ; D

In terminal

# Using npm
% npm install tailwindcss

# Using Yarn
% yarn add tailwindcss
Enter fullscreen mode Exit fullscreen mode

Second example:

In this case, add autoprefixer library.
Where the library will take care of prefixing all CSS classes so that all browsers understand.

  • autoprefixer

Also add CSS preprocessors are in charge of transforming the language rules used by Tailwind CSS into CSS code that is understandable by the browser, in this case PostCSS.

  • postcss-cli

πŸ‘‡

In terminal

tailwind_test % npm install tailwindcss autoprefixer postcss-cli

npm notice created a lock file as package-lock.json. You should commit this file.
npm WARN project@1.0.0 No description
npm WARN project@1.0.0 No repository field.

 +autoprefixer@9.8.6
 +postcss-cli@7.1.1
 +tailwindcss@1.7.3
added 172 packages from 142 contributors and audited 172 packages in 20.567s

10 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

tailwind_test % 
Enter fullscreen mode Exit fullscreen mode

4:

NPX TAILWINDCSS: We can run the next command that we will see next.

-npx tailwindcss init

That this command will create the folder config empty

tailwind.config.js

πŸ‘‡

In terminal

tailwind_test % npx tailwindcss init

   tailwindcss 1.7.3

   βœ… Created Tailwind config file: tailwind.config.js

tailwind_test % 
Enter fullscreen mode Exit fullscreen mode

In our visual studio code it looks like this below

Alt Text

LATER:

Create a file: We need to create a file named postcss.config.js. We can create it in your terminal or in your code editor.

Create file

  • touch postcss.config.js

See all files

  • ls

πŸ‘‡

In terminal

tailwind_test % touch postcss.config.js
tailwind_test % ls
node_modules        package-lock.json   package.json        postcss.config.js   tailwind.config.js
Ttailwind_test % 
Enter fullscreen mode Exit fullscreen mode

In our visual studio code it looks like this below

Alt Text

5:

Config file postcss.config.js in VS code.

πŸ‘‡πŸ“„

In file postcss.config.js

module.exports = {
    plugins: [
        require('tailwindcss'),
        require('autoprefixer')
    ]
}
Enter fullscreen mode Exit fullscreen mode

6:

Config File CSS: In documentation tailwind. Add Tailwind to your CSS.

https://tailwindcss.com/docs/installation

Use the @tailwind directive to inject Tailwind's base, components, and utility styles into your CSS:

πŸ‘‡πŸ“„

In file example.css

@tailwind base;

@tailwind components;

@tailwind utilities;
Enter fullscreen mode Exit fullscreen mode

7:

Config File tailwind.config.js: In documentation tailwind. Add Tailwind to your CSS.

https://tailwindcss.com/docs/installation you can search the working config in the documentation.

Is for change config for example in this case font family and extend

πŸ‘‡πŸ“„

In file tailwind.config.js

module.exports = {
  purge: [],
  theme: {
    fontFamily: {
      display: ['Gilroy', 'sans-serif'],
      body: ['Graphik', 'sans-serif'],
    },
    extend: {
      colors: {
        cyan: '#9cdbff',
      },
    }
  },
  variants: {},
  plugins: [],
}
Enter fullscreen mode Exit fullscreen mode

8:

Create HTML for file CSS and modify script package.json.

πŸ‘‡πŸ“„

In file index.html

<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Tailwind CSS</title>
    <link rel="stylesheet" href="css/style.css">
</head>

<body>

    <h1>Hello world</h1>

</body>

</html>
Enter fullscreen mode Exit fullscreen mode

The script will create the file style.css

πŸ‘‡πŸ“„

In file package.json

"scripts": {
    "build": "postcss css/tailwind.css -o public/css/style.css"
  },
Enter fullscreen mode Exit fullscreen mode

πŸ‘‡

In terminal

tailwind_test % npm run build

>project@1.0.0 build /tailwind_test
>postcss css/tailwind.css -o public/css/style.css

risk - There are upcoming breaking changes: removeDeprecatedGapUtilities
risk - We highly recommend opting-in to these changes now to simplify upgrading Tailwind in the future.
risk - https://tailwindcss.com/docs/upcoming-changes
tailwind_test %

Enter fullscreen mode Exit fullscreen mode




In our visual studio code it look like this below where file style was created

Alt Text

Additionally to all this as advice and more.

You can add other npm facilities: This command will create a file where you will see all css properties for tailwind.

πŸ‘‡

In terminal

tailwind_test % npx tailwindcss init tailwind.cong.full.js --full

tailwindcss 1.7.3

βœ… Created Tailwind config file: tailwind.cong.full.js

tailwind_test %

Enter fullscreen mode Exit fullscreen mode




recommended plug-in for VS code: Tailwind CSS IntelliSense

  • This extension helps you autocomplete classes and styles that are using.

Alt Text

Another tip, if you have any problem with your extensions, It probably that you need close and open the code editor.

I share some sources with you of this blog

Tailwind css course at Platzi https://platzi.com
Tailwind documentation https://tailwindcss.com/docs/installation

Now we have done it! πŸ‘

But If you have a question or feedback, please write to me!πŸ™‚

Top comments (0)