21

Is there such an option to create a Module that is linked to a component, which does not have a css file upon creation?

e.g.

The default way of doing this for me so far is the following:

ng generate module name / ng generate component name

And I get the basic structure of a component: name.component.css name.component.html name.component.spec.ts name.component.ts name.module.ts

And I want to create the following with only ONE query:

name.component.html name.component.spec.ts name.component.ts name.module.ts

e.g. something like:

ng g m name + c name - css ... you get the idea.

Is this possible, and if yes, how?

Tanasos
  • 3,928
  • 4
  • 33
  • 63

4 Answers4

45

Minimalist Angular Cli generate example

ng g c hero-component --flat -t -s --skip-Tests

  • -s for inline css, preventing style file creation
  • --flat to prevent folder creation
  • -t for inline template, preventing html file creation
  • --skip-Tests to prevent .spec file creation

Link to the Angular doc reference https://angular.io/cli/generate#component

With all these parameters together,

The cli creates a single .ts file in the current folder and links it in the module.

Royi Namir
  • 144,742
  • 138
  • 468
  • 792
Vishesh Mishra
  • 988
  • 9
  • 12
6

You can use ng generate -is for inline-style, which will not generate css file separately, but will keep css inside component (inline).

Roberto Zvjerković
  • 9,657
  • 4
  • 26
  • 47
  • I get the following response: `ng generate -is Schematic "-is" not found in collection "@schematics/angular". Error: Schematic "-is" not found in collection "@schematics/angular". at SchematicEngine.createSchematic ........` – Tanasos May 09 '18 at 06:23
  • `ng g c component -is` and I get a `node_modules appears empty, you may need to run `npm install` `, needless to say, it is not empty, and I ran npm install again, but it does not work for me. What am I doing wrong? – Tanasos May 10 '18 at 08:57
3

The latest, correct answer is:

ng g c MyComponent --style none

It will NOT create style file and it will NOT have any inline styles.

Ap0st0l
  • 515
  • 4
  • 26
0

Although late, But this might help geeks who already have a created component (in my case 'abc') having

 1. abc.component.html
 2. abc.component.css
 3. abc.component.spec.ts
 4. abc.component.ts

and not using other files than abc.component.ts Then can delete the other 3 files and modify abc component's @Component decorator to

@Component({
  selector: 'app-abc',
  template: ``,
  styles: []
})
EnthuCoder
  • 67
  • 8