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
Newsletter
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

  • SSRF Prevention in C#: Securing File Imports From User-Supplied URLs
  • The Three Tiers of Agentic Incident Response: When to Trust AI Autonomy
  • Beyond the Endpoint: How Agent Cards Enable Discovery, Interoperability, and Trust
  • Giving AI Agents Safe Access to Legacy Systems: Introducing legacy2mcp

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  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
DZone Core CORE ·
Oct. 04, 21 · Opinion
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
11.6K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

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

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • 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