Angular CLI Generate Library with SASS

余生颓废 提交于 2020-01-01 05:11:28

问题


I have an Angular6 app that I am trying to create a library for. I was able to generate a library project but when I generate the component for the library, Angular CLI is creating it with .css files.

How can I get it to create .scss files?

Here are the commands I'm using to create the project:

ng new example-app --style=scss
rename example-app example
cd example
ng generate library example --prefix=exam --style=scss
ng generate component test --project=example

The --style=scss option on the ng generate library command does not have an effect, I still get CSS files in my test component folder.


回答1:


You can fix it by overriding schematics for your project in your angular.json like in the example below:

"example": {
    "root": "projects/example",
    "sourceRoot": "projects/example/src",
    "projectType": "library",
    "prefix": "exam",
    "schematics": {
      "@schematics/angular:component": {
        "styleext": "scss"
      }
    },
 ....
}

or you can set this value via angular-cli like so:

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

After that try to generate component, it should have scss extension.



来源:https://stackoverflow.com/questions/50818889/angular-cli-generate-library-with-sass

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