Changing SCSS to CSS using the SASS Package

Introduction :

This documentation outlines the process of converting SCSS (Sassy CSS) files to standard CSS (Cascading Style Sheets) in a project's assets directory using the SASS package. SCSS is a preprocessor for CSS, and SASS is a popular choice for transforming SCSS into CSS efficiently. This guide provides step-by-step instructions on installing the SASS package, configuring it in your project, and converting SCSS files to CSS.

  • Prerequisites

    Before proceeding, ensure that you have the following prerequisites:

    Node.js installed on your system.

    A project directory with SCSS files that you want to compile into CSS.

Installation :

Install the SASS package using npm (Node Package Manager) by running the following command:

npm install sass

This command will download and install the SASS package and its dependencies into your project.

Configuration :

To configure SASS for your project, follow these steps:

  • 1. Open your project's package.json file. If you don't have one, you can create it by running npm init and following the prompts.

  • 2. Inside the package.json file, locate the "scripts" section. If it doesn't exist, create one:

    "scripts": { // ...existing scripts... }

  • 3. Add a script that specifies the compilation process from SCSS to CSS. You can name the script as you prefer, but for this example, we'll name it "sass." The script should look like this:

    "scripts": { "sass": "sass ./public/assets/scss:./public/assets/css/" }

    In the script above, replace ./public/assets/scss with the path to your SCSS files and ./public/assets/css with the destination directory for your compiled CSS files.

  • 4. Add a script that specifies the compilation compressed process from SCSS to CSS. You can name the script as you prefer, but for this example, we'll name it "sass-min." The script should look like this:

    "scripts": { "sass-min": "sass ./public/assets/scss:./public/assets/css/ --style compressed" }

    In the script above, replace ./public/assets/scss with the path to your SCSS files and ./public/assets/css with the destination directory for your compiled CSS files.

  • 5. Save the package.json file.

Compiling SCSS to CSS :

With the SASS package and script configured, you can now compile your SCSS files to CSS with the following steps:

  • 1. Open your terminal or command prompt.

  • 2. Navigate to your project's root directory if you're not already there.

  • 3. Execute the following command to run the "sass" script:

    npm run sass

    This command will initiate the SCSS to CSS compilation process using the SASS package.

  • 4. Execute the following command to run the "sass-min" script:

    npm run sass-min

    This command will initiate the SCSS to CSS compilation compressed process using the SASS package.

  • 5. Once the process is complete, the compiled CSS files will be generated in the specified destination directory (e.g., ./public/assets/css).

Conclusion :

You have successfully configured and used the SASS package to convert SCSS files to CSS in your project. This allows you to take advantage of SCSS's powerful features while ensuring that your web application uses standard CSS for styling.