You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Angular 6使用Angular CLI生成组件时无法生成.scss文件求助

Fixing Angular 6 CLI to Generate .scss Files for Components

Hey there! I totally get the frustration when the old config trick doesn't work in newer Angular versions. Angular 6 changed up the structure of angular.json, so the defaults.styleExt setting you tried is no longer valid here. Let's get this sorted step by step:

Step 1: Update your angular.json configuration

In Angular 6+, the style extension setting lives under the schematics section of your project's config, not the old defaults block. Here's how to set it up:

  1. Open the angular.json file in your project's root directory.
  2. Locate your project's entry under the projects object (it should match your project name).
  3. If there's no schematics key inside your project's block, add it.
  4. Add the component-specific schematic config to enforce .scss styles:
"projects": {
  "your-project-name": {
    // ... other existing config like architect, etc.
    "schematics": {
      "@schematics/angular:component": {
        "style": "scss"
      }
    }
  }
}

Step 2: Verify the change

Save the angular.json file, then run a component generation command like:

ng generate component test-component

You should now see a test-component.component.scss file created alongside your component, instead of .css.

Bonus: Override for single components (if needed)

If you ever need to generate a component with a different style extension just once, you can use the --style flag directly in the command:

ng g c temp-component --style=css

That should do the trick! Let me know if you run into any hiccups.

内容的提问来源于stack exchange,提问作者pooja patil

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 03:45:13