DEV Community

Gaëtan Redin
Gaëtan Redin

Posted on • Originally published at Medium on

Simplifying SCSS File Imports in Angular

How to Simplify SCSS File Imports in Angular

Hey, we all have ever seen something like this in our SCSS files:

@import '../../../../../my-css-file';
Enter fullscreen mode Exit fullscreen mode

But that’s not really sexy, right? Thanks to the power of the pre-processor, we can now just code:

@import 'my-css-file';
Enter fullscreen mode Exit fullscreen mode

How? We need to update our angular.json like this:

{
    ...
    "projects": {
        "<project_name>": {
            ...
            "architect": {
                "build": {
                    "builder": "@angular-devkit/build-angular:browser",
                    "options": {
                        ...
                        "stylePreprocessorOptions": {
                            "includePaths": [<path_to_my_scss_folder>]
                        }
                        ...
                    }
                }
                ...
            }
        }
    }
    ...
}
Enter fullscreen mode Exit fullscreen mode

Thanks for reading.

Learn More

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (1)

Collapse
 
diosvo profile image
Dios Vo • Edited

If your Angular version is greater than 12, you can use @use instead.

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay