【问题标题】:@angular/cli: 1.4.1 Angular Generate Component but it returns home.component.css@angular/cli:1.4.1 Angular 生成组件,但它返回 home.component.css
【发布时间】:2018-02-20 15:55:33
【问题描述】:
$npm install -g @angular/cli
$ng new angular --routing --style=sass
$ng g c home
 "apps": [
    {
      "styles": [
           "styles.sass"
      ],
    }

"defaults": {
    "styleExt": "sass",
    "component": {
    }
  }

我想在 Angular 中使用 sass 样式,我使用 angular cli,我尝试生成它返回的组件,它返回带有前缀 css 的样式。你能帮我解决这个问题吗?提前感谢您的回答。

【问题讨论】:

  • 如何生成组件?
  • @jhen 问题是:ng g c home
  • 我用这个ng g c home
  • 在我使用 @angular/cli: 1.3.2 之前它可以工作,但 @angular/cli: 1.4.1 它不工作。
  • 我将 Angular CLI 降级到 1.3.2,直到他们解决了这个问题。

标签: node.js angular angular-cli angular-components


【解决方案1】:

要覆盖默认样式,可以使用选项--style [css|scss|sass]

ng g c home --style=css

【讨论】:

  • 如果您已经定义了styleExt,则不必每次都附加--style。这个答案作为一个临时解决方法可能很好,但你不应该真的这样做。
  • 暂时没问题,直到bug修复
【解决方案2】:

这是我的默认设置:

"defaults": {
  "styleExt": "scss",
  "prefixInterfaces": false,
  "inline": {
    "style": false,
    "template": false
  },
  "spec": {
    "class": false,
    "component": true,
    "directive": true,
    "module": false,
    "pipe": true,
    "service": true
  }
}

否则,您可以重命名它。

【讨论】:

    【解决方案3】:

    我刚刚从@angular/cli@1.0.3 迁移到@angular/cli@1.4.2,我也面临同样的问题。原来这是由于 v1.4.1 中引入的一个错误,所以我们只能等待一个新的 angular-cli 版本来修复这个错误。 在 v1.4.1 中,apps.prefix 也被忽略,但在 v1.4.2 中已修复。

    同时,可以使用@Derlin 提供的解决方法。

    关于这个主题的github问题:

    更新:

    该问题已在 @angular/cli@1.4.3 中修复。检查this release note

    @angular/cli: 生成组件考虑默认样式扩展 现在的项目

    【讨论】:

      猜你喜欢
      • 2018-11-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-04
      相关资源
      最近更新 更多