DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • How to Effortlessly Host Your Angular Website on GitHub Pages
  • Angular vs. Flutter for Web App Development: Know Which One Is Best?
  • Difference Between Bootstrap and AngularJS in 2022
  • The Best Javascript Frameworks for 2022

Trending

  • DevOps and Platform Engineering Readiness Checklist: Everything Needed for a Scalable, Secure, High-Velocity Delivery Platform
  • Lambda-Driven API Design: Building Composable Node.js Endpoints With Functional Primitives
  • Mastering Fluent Bit: Beginners' Guide for Contributing to our CNCF Project Docs
  • Why AI-Generated Code Breaks Your Testing Assumptions
  1. DZone
  2. Coding
  3. Frameworks
  4. A Brief Guide to Using Sass/SCSS in an Angular App

A Brief Guide to Using Sass/SCSS in an Angular App

I was wondering how to structure the pre-processor scripting language Sass/SCSS files in an Angular project. And, turns out there are several solutions.

By 
Alexey Shepelev user avatar
Alexey Shepelev
DZone Core CORE ·
Oct. 04, 21 · Opinion
Likes (13)
Comment
Save
Tweet
Share
11.3K Views

Join the DZone community and get the full member experience.

Join For Free

Method 1

To Keep All Style Files in the /Styles Folder

In this case, we create all files in the /styles folder by following a pattern structure:

Shell
 
styles 
	├── base 
	├── components
	└── xxxxx


One of the popular methods to structure files in this way is the 7-1 pattern suggested in the sass documentation. More details can be found here.

The Pros of This Approach:

  1. All style files are in one place.

  2. Style building becomes faster.

Cons:

  1. The developer must know where the required file should be located.

  2. The file structure may get messy in a large project.

Method 2

To Keep Each Style File in the Component and Add Global Styles to the /Styles Folder

In this case, we leave component style files in components and move global styles to /styles. Files with variables and mixins are also added to the /styles folder and then imported into the component style files. The /styles folder looks the same as in the first method but has no component styles.

The Pros of This Approach:

  1. Components have their style files.

  2. It is easier to achieve a clean structure for style files.

Cons:

  1. Building style files can get slower in a large project.

Method 3

To Move All Component Styles to a Single File and Keep Global Styles in the /Styles Folder

It looks like the first method except that component styles are contained in a single file that is stored in the components folder.

The Pros of This Approach:

  1. Components have their single style file which can be quickly accessed.

  2. Style building is faster.

Cons:

  1. You always need to import the common component style file into the style file of a new component.

Of the three methods found, the second one seems to be the most effective for an Angular application. The first one is more suitable for layout projects without frameworks. The third method looks rather strange, although it may be convenient.

Thank you for your time, and have a nice day!

AngularJS app

Opinions expressed by DZone contributors are their own.

Related

  • How to Effortlessly Host Your Angular Website on GitHub Pages
  • Angular vs. Flutter for Web App Development: Know Which One Is Best?
  • Difference Between Bootstrap and AngularJS in 2022
  • The Best Javascript Frameworks for 2022

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook