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

半腔热情 提交于 2020-08-06 15:39:10

问题


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:


回答1:


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.


来源:https://stackoverflow.com/questions/51011228/scss-file-imports-using-tilde-is-not-working-in-angular-6

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!