Angular CLI:从现有项目生成SASS项目

时间:2017-01-02 14:13:02

标签: angular sass angular-cli

我开始研究Angular CLI生成的项目,并意识到我忘记了--style=sass标志。 有没有办法转换我的项目以使用Angular CLI启用SASS?

4 个答案:

答案 0 :(得分:8)

您可以在现有项目上设置默认样式

ng set defaults.styleExt scss

并在angular-cli.json文件中将 style.css 更改为 style.scss

"apps":[{
  "styles":[
     "styles.scss"
   ]
}]

答案 1 :(得分:4)

在角度cli 6中,这是被剥夺的

ng set defaults.styleExt scss

你应该使用这个

ng config defaults.styleExt = scss

答案 2 :(得分:4)

在Angular 6+中,如果您在执行ng config defaults.styleExt = scss 之后收到控制台警告 之所以这样,是因为single dashes are not supported anymore

Schema validation failed with the following errors:
 Data path "" should NOT have additional properties(defaults).

您可以运行以下命令来更改原理图

ng config schematics.@schematics/angular:component.styleext scss

您需要进行两次手动更改

  • .css文件重命名为根文件夹中的.scss
  • 使用"styles": ["src/styles.scss"],
  • 更新 angular.json 文件

答案 3 :(得分:2)

只需将现有的css文件(如果有的话)重命名为sass并将其添加到angular-cli.json:

//
//  main.cpp
//  This code doesn't compile
//  but it's for clarification purposes
//  Created by Måns Nilsson on 2017-01-02.
//  Copyright © 2017 Måns Nilsson. All rights reserved.
//

#include <iostream>

using namespace std;

int main(int argc, const char * argv[]) {
    int currval;
    int otherval;
    int arrlength;
    cout<<"How many elements would you like to allocate?"<<endl<<"Your input: ";
    cin >> arrlength;
    int numlist[arrlength];

    //User inputs the element values and variables are assigned to
    //point directly to each element
    for(int i=0;i<arrlength;i++) {
        cout<<"Enter a value for element "<<(i + 1)<<": ";
        cin >> currval;
        numlist[i] = currval;
        int &var(i) = numlist[i];
    }

        cout<<"Enter the index of the element you want to modify: ";
        cin >> currval;
        cout<<"Enter a new value for element "<<currval<<": ";
        cin >> otherval;
        var(currval-1) = otherval;

    return 0;
}

另请查看此文件中的app / styles部分 - 您也应该在此处重命名文件名