Using Tailwind CSS in SCSS-Based Projects #17274
alicannck
started this conversation in
Show and tell
Replies: 2 comments 2 replies
-
You are welcome to suggest any additions or improvements. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Are scss files, other than the global one, where we define themes. able to use themes variables directly or do I also have to import them? |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Using Tailwind CSS in SCSS-Based Projects
Tailwind CSS is a utility-first CSS framework that allows developers to style elements quickly and efficiently. SCSS, on the other hand, is a preprocessor used for writing more organized, flexible, and maintainable CSS. In this article, I will walk you through the steps of integrating Tailwind CSS into SCSS-based projects. This guide will help those who want to leverage both the advantages of SCSS and the flexibility and speed offered by Tailwind, taking their projects to the next level.
Initialize the Project and Install Dependencies
The first step in setting up Tailwind CSS in your SCSS-based project is to initialize a new Node.js project. This is done using
npm init -y
, which generates apackage.json
file in your project directory. This file will hold all the information about your project and its dependencies.Run the following command in your terminal:
Next, you'll need to install Tailwind CSS and the required PostCSS dependencies. These are necessary to enable Tailwind CSS to work in your SCSS project. To install them, run the following command:
No Need for
tailwind.config.js
In this setup, we do not need to create a
tailwind.config.js
file because we are directly importing Tailwind CSS into our SCSS file from thenode_modules
directory.Configure PostCSS
Next, you need to create a
postcss.config.mjs
file in the root of your project. This file is used to configure PostCSS and its plugins.To create this file, run the following command:
Once the file is created, open it and add the following configuration:
Modify
package.json
ScriptsNext, you need to modify the
scripts
section of yourpackage.json
file to set up a development command for Tailwind CSS and SCSS.Open your
package.json
file and update thescripts
section like this:Import Tailwind in SCSS
Now, open your
style.scss
file (or create one insidesrc/scss/
) and import Tailwind CSS by adding the following line at the top:Start Development Server
Finally, to start your project and begin the development process, run the following command in your terminal:
Recommended VS Code Extensions
For a smoother development experience, I recommend installing the following Visual Studio Code extensions:
1. Live Server
Live Server is an extension that allows you to quickly open your project in the browser and automatically reloads it whenever you make changes to your files. This can be incredibly useful for seeing live updates of your project while you work.
To install Live Server, search for Live Server in the Extensions Marketplace and click Install.
2. Live Sass Compiler
Live Sass Compiler is an extension that compiles your SCSS files to CSS automatically and provides live updates. This helps you avoid manually running the build command every time you make a change to your SCSS files.
To install Live Sass Compiler, search for Live Sass Compiler in the Extensions Marketplace and click Install.
By using these extensions, you'll have an even more efficient and seamless development workflow, allowing for live updates as you work on your SCSS and Tailwind CSS project.
Installing Tailwind CSS IntelliSense
Add this line to the file where you imported Tailwind (settings.json)
Beta Was this translation helpful? Give feedback.
All reactions