Angular CLI使用SASS生成库 [英] Angular CLI Generate Library with SASS

查看:76
本文介绍了Angular CLI使用SASS生成库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要为其创建库的 Angular6 应用。我能够生成一个库项目,但是当我生成库的组件时,Angular CLI会使用 .css 文件创建它。

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.

如何创建 .scss 文件?

以下是我用来创建项目的命令:

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

-style = scss < ng生成库命令上的/ code>选项无效,我仍然在测试组件文件夹中获得CSS文件。

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.

推荐答案

您可以通过在角度覆盖项目的示意图来解决此问题.json 如下例所示:

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"
      }
    },
 ....
}

,也可以像下面这样通过angular-cli设置该值:

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

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

尝试生成组件之后,它应该具有 scss 扩展名。

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

这篇关于Angular CLI使用SASS生成库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆