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

Add new flag `--sfc` to create standalone, inline template and inline style components

Open pavankjadda opened this issue 3 years ago • 5 comments

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

pavankjadda avatar Sep 12 '22 14:09 pavankjadda

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
        }
      },

clydin avatar Sep 13 '22 14:09 clydin

Actually @dgp1130, mentioned to combine --inline-style and --inline-template into a single option as it's likely that these are used together.

alan-agius4 avatar Sep 14 '22 08:09 alan-agius4

Actually @dgp1130, mentioned to combine --inline-style and --inline-template into a single option as it's likely that these are used together.

Any plans to include standalone into that?

pavankjadda avatar Sep 15 '22 02:09 pavankjadda

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.

dgp1130 avatar Sep 15 '22 02:09 dgp1130

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.

angular-robot[bot] avatar Sep 15 '22 13:09 angular-robot[bot]