angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

ng generate does not respect defaults.styleExt settings

Open onwsk8r opened this issue 9 years ago • 11 comments

- [x] bug report -> please search issues before submitting
- [ ] feature request

Versions.

> ng --version
@angular/cli: 1.4.1
node: 6.11.3
os: linux x64
@angular/animations: 4.3.6
@angular/common: 4.3.6
@angular/compiler: 4.3.6
@angular/core: 4.3.6
@angular/forms: 4.3.6
@angular/http: 4.3.6
@angular/platform-browser: 4.3.6
@angular/platform-browser-dynamic: 4.3.6
@angular/router: 4.3.6
@angular/cli: 1.4.1
@angular/compiler-cli: 4.3.6
@angular/language-service: 4.3.6
typescript: 2.3.4
> npm --version
3.10.10

Repro steps.

After setting the default....

> ng set --global defaults.styleExt=scss
> grep styleExt ~/angular-cli.json
    "styleExt": "scss"

When I make a new project...

> ng new my_proj && cd my_proj
...
> grep styleExt ./.angular-cli.json
    "styleExt": "scss", 

I have a file called app.component.scss with the correct styleUrl in app.component.ts.

However, when I ng g component my-awesome-component, I end up with my-awesome.component.css and the equivalent styleUrl in the Typescript file.

Desired functionality.

I would like it to respect the settings in .angular-cli.json like ng new does.

onwsk8r avatar Sep 10 '17 07:09 onwsk8r

It is not only the styleExt property, but also the prefix property which is ignored. in my .angular-cli.json I have

{
  "apps": [
    {
      "prefix": "ts",
    }
  ],
  "defaults": {
    "styleExt": "scss",
    "component": {}
  }
}
"

but when generating a new component ng g +my-module/new-component I end up with a .css file instead of a .scss as already reported, but also the component selector is app-new-component instead of ts-new-component

I think that this is a serious regression compared to v1.3.2

alaindeurveilher avatar Sep 10 '17 10:09 alaindeurveilher

Actually all defaults are ignored in the .angular-cli.json file. If you use the options directly in the command line everything still works file.

bboehm86 avatar Sep 10 '17 10:09 bboehm86

Same with me, I raised issue over SO for this, Here is link , https://stackoverflow.com/questions/46139997/angular-cli-1-4-1-ng-always-generate-spec-file-and-css-even-default-prefix-is

I thought , its only with me, but seems CLI team broke things very seriously here. I hope by downgrading it solve temporary.

VirajNimbalkar avatar Sep 10 '17 11:09 VirajNimbalkar

The style extension issue was already reported here: https://github.com/angular/angular-cli/issues/7624

@Brocco I believe there is a problem with the schematics library. I found two troublesome commits, tested with the command ng g c test:

128187e4c1b20aa5e6231099f1cb80e094a2d8d9 Problems that started here:

  1. default style extension ignored
  2. alias c doesn't work, using component does.

884385e4735a74ee593cc7d510258b9aca63d4f0

  1. alias c came back to life
  2. default style extension is still ignored
  3. default inlineTemplate is ignored starting from this commit

Hope this helps! :)

shmool avatar Sep 10 '17 12:09 shmool

Dupe of #7624

rafaelss95 avatar Sep 10 '17 13:09 rafaelss95

Even though this is a dupe I'm going to leave it open since #7647 will close this when it gets merged (and as of now, Travis is passing, so it just needs a review). And sorry for posting a dupe- I'm not sure how I missed 7624.

onwsk8r avatar Sep 11 '17 14:09 onwsk8r

Is this really still open?

JustDoItSascha avatar Jun 19 '18 14:06 JustDoItSascha

This works

{
    "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
    "version": 1,
    "newProjectRoot": "projects",
    "projects": {
        "my-app": {
            "root": "",
            "sourceRoot": "src",
            "projectType": "application",
            "prefix": "app",
            "schematics": {
                "@schematics/angular:component": {
                    "styleext": "scss"
                }
            },
            ...
       }
   }
}

chris31389 avatar Jul 05 '18 08:07 chris31389

It's sad but on:

Angular CLI: 7.3.7
  Node: 10.14.1
  OS: win32 x64
  Angular: 7.2.11
  ... animations, common, compiler, compiler-cli, core, forms
  ... http, language-service, platform-browser
  ... platform-browser-dynamic, router, service-worker
  
  Package                           Version
  -----------------------------------------------------------
  @angular-devkit/architect         0.13.7
  @angular-devkit/build-angular     0.13.7
  @angular-devkit/build-optimizer   0.13.7
  @angular-devkit/build-webpack     0.13.7
  @angular-devkit/core              7.3.7
  @angular-devkit/schematics        7.3.7
  @angular/cdk                      7.3.6
  @angular/cli                      7.3.7
  @angular/flex-layout              7.0.0-beta.24
  @angular/material                 7.3.6
  @angular/pwa                      0.13.7
  @ngtools/webpack                  7.3.7
  @schematics/angular               7.3.7
  @schematics/update                0.13.7
  rxjs                              6.4.0
  typescript                        3.2.4
  webpack                           4.29.0

ng generate component is still ignoring default settings on angular.json:

      "root": "",
      "sourceRoot": "src",
      "projectType": "application",
      "prefix": "ids",
      "schematics": {
        "@schematics/angular:component": {
          "inlineStyle": false,
          "inlineTemplate": false,
          "spec": false,
          "styleext": "scss"
        }
      },

Actually it's only happening on "spec" and "styleext". Prefix and directories are working OK.

JosepAlacid avatar Apr 11 '19 20:04 JosepAlacid

On Angular 8 , in my case, this issue is only happening after install @ngxs/schematics. Once this option is removed, ng g component is working fine again. Hope this helps.

JosepAlacid avatar Jul 11 '19 08:07 JosepAlacid

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.