Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SCSS file imports using ~ (tilde) is not working in Angular 6

Tags:

sass

angular

I have two question regarding scss file imports in Angular6

  1. Do I need to import my partials in all of my component.scss files after having imported it once in global src/sass/styles.scss. Shouldn't importing it once be enough?
  2. How do I import SCSS partials using import shortcut ~ ? All my partials are contained in src/sass folder.

This is fine: @import '../sass/variables';//in app.component.scss

But this throws error: @import '~sass/variables':

ERROR in ./src/app/app.component.scss Module build failed: @import '~sass/variables'; ^ File to import not found or unreadable: ~sass/variables. in C:\Users\sandeepkumar.g\Desktop\nodebook\tdlr-this\src\app\app.component.scss (line 2, column 1)

`

angular.json:

"styles": [
              ...
              "src/sass/styles.scss"
            ],

My folder structure:

enter image description here

like image 389
dasfdsa Avatar asked Jun 24 '18 15:06

dasfdsa


People also ask

What is tilde in SCSS import?

WEB-26512 '~' not work in sass editor when is point to src. Subtask of 1 issue (0 unresolved) WEB-17533 Support for webpack resolve.modulesDirectories. 34 13. Webpack lets you specify the project's root and then tilde (~) is used to import scss files relative to the root set in the webpack config file.

What is difference between @USE and @import in SCSS?

Fundamentally both rules do the same thing - load members inside another module. The main differences is how they handle members. @import makes everything globally accessible in the target file.


1 Answers

Answering my own question. It turns out both of these problems are "bug" in Angular 6.

  1. Yes, if you want to use any .scss file code in any component.scss, they have to be imported in that component.scss. Issue.
  2. ~ (Tilda) has stopped working since Angular6. Issue. Use ~src instead to import scss.
like image 82
dasfdsa Avatar answered Nov 15 '22 21:11

dasfdsa