theMayer
theMayer

Reputation: 16177

Is there a way to prevent Angular from generating a blank component.scss file?

In angular, when you generate a new component (i.e. ng generate component) it creates a new *.scss file to go along with the new component. However, these files are rarely used. Is there a way to suppress creation of this file, and just have it generate the code, spec, and template?

Upvotes: 6

Views: 1858

Answers (2)

R. Richards
R. Richards

Reputation: 25161

If you want to avoid getting a scss file for a component, use the --inlineStyle=true (or -s=true) option while using the ng generate component command (or ng g c <comp-name> -s=true for short), as @pzaenger shows in their answer.

If you would like that same behavior to occur by default for a new project, you can use the --inlineStyle=true (or -s=true) option while using the ng new command.

If you would like that same behavior to be default for an existing project, you will need to add some stuff to your angular.json file. See below.

...
"projects": {
    "<your project name>": {
    "root": "",
    "sourceRoot": "src",
    "projectType": "application",
    "prefix": "app",
    "schematics": {
        "@schematics/angular:component": {
        "inlineStyle": true,
        "styleext": "scss"
        }
    },
...

Add "inlineStyle": true in the proper place like shown above.

Then, when you run ng generate component, the styles will be inline by default.

2019-03-20 Update: updated answer to work with Angular CLI 7.x. The argument names changed since the original post.

Upvotes: 6

pzaenger
pzaenger

Reputation: 11992

Use --inline-style, or simply -s:

Specifies if the style will be in the ts file.

Works also for the HTML-markup (--inline-template) and so on.

(Though @R.Richards was faster, I hope my answer is fine)

Upvotes: 1

Related Questions