Angular中處理scss快捷導入的方式

  • 前言:
    在項目中通常都有對SCSS文件進行模塊化的處理,好比varible.scss | mixin.scss,這種Global Scss
    Theme Define.
  • 問題:
    當項目文件變得很錯綜複雜的時候尤爲是在使用Angular進行開發的項目中,
    當其餘的主題scss文件須要去引入這個Global scss theme時, 很容易形成一個引用路徑很冗長的問題.例如 @import
    '../../../../../stylings/varible.scss';
  • 解決方案:
    在angular.json中進行項目的CI配置.

#angular.json
{
            ...
            "apps": [{
                "root": "src",
                ...
                "stylePreprocessorOptions": {
                    "includePaths": [
                      "./stylings"
                    ]
                }
            
            }]
}

// hello.component.scss
@import "variables"; // 直接引入 variables, 和 ../../../stylings/ 說拜拜吧

h1 {
    color: $brand-color;
}

Think: 同名怎麼處理?可否加入前綴做爲區分?借鑑實現Angular Material的scss導入方式@import '~@angular/material/theme.scss'?css

相關文章
相關標籤/搜索