Add new flag `--sfc` to create standalone, inline template and inline style components
Command
generate
Description
After Standalone components rolled out in v14, many of the angular devs started using single file standalone components as default. They just look cleaner, less number of files and forces us to create simple components i.e. don't put too much in single file, hence increases the re-usability and readability
At present we use
ng generate component COMPONENT_NAME --standalone --inline-style --inline-template
this can be simplified to
ng generate component COMPONENT_NAME --sfc
Describe the solution you'd like
add a new flag called --sfc to CLI that creates standalone, inline template and inline style component
Describe alternatives you've considered
At present we supply 3 flags to achieve this behaviour
ng generate component COMPONENT_NAME --standalone --inline-style --inline-template
This can be partially achieved today with ng generate component COMPONENT_NAME --standalone -st. The standalone option does not yet have a shorthand name due to it still being in developer preview.
Alternatively, if a project will always create components in this form, the options can be defaulted within the angular.json file so that they are also enabled when executing just ng generate component COMPONENT_NAME. The schematics section of the configuration would look similar to the following as example:
"schematics": {
"@schematics/angular:component": {
"inlineStyle": true,
"inlineTemplate": true,
"standalone": true
}
},
Actually @dgp1130, mentioned to combine --inline-style and --inline-template into a single option as it's likely that these are used together.
Actually @dgp1130, mentioned to combine
--inline-styleand--inline-templateinto a single option as it's likely that these are used together.
Any plans to include standalone into that?
Yes, we did recently chat about merging these two options. I think @alxhub wanted a different name than --sfc, but I forget what his preference was.
I'm fully in support of merging the options. 99% of the time users use them together anyways.
We'd probably start out without standalone (though we'd probably support --sfc --standalone). If we ever decide to do standalone by default, then that would probably also apply to --sfc in the same way.
This feature request is now candidate for our backlog! In the next phase, the community has 60 days to upvote. If the request receives more than 20 upvotes, we'll move it to our consideration list.
You can find more details about the feature request process in our documentation.