Second, any time you have a question about the behavior of Ember CLI you can type
ember help—up to and including about specific commands! So, here, you can run
ember help generate component, and it’ll print this:
ember help generate component
Requested ember-cli commands:
ember generate <blueprint> <options...>
Generates new code from blueprints.
--dry-run (Boolean) (Default: false)
--verbose (Boolean) (Default: false)
--pod (Boolean) (Default: false)
aliases: -p, -pods
--classic (Boolean) (Default: false)
--dummy (Boolean) (Default: false)
aliases: -dum, -id
--in-repo-addon (String) (Default: null)
aliases: --in-repo <value>, -ir <value>
--in (String) (Default: null) Runs a blueprint against an in repo addon. A path is expected, relative to the root of the project.
component <name> <options...>
Generates a component.
--path (String) (Default: components)
aliases: --no-path (--path="")
--component-class (@ember/component, @glimmer/component, @ember/component/template-only, "") (Default: --no-component-class)
aliases: -cc (--component-class=@ember/component), -gc (--component-class=@glimmer/component), -tc (--component-class=@ember/component/template-only), -nc (--component-class=""), --no-component-class (--component-class=""), --with-component-class (--component-class=@glimmer/component)
--component-structure (flat, nested, classic) (Default: flat)
aliases: -fs (--component-structure=flat), -ns (--component-structure=nested), -cs (--component-structure=classic)
As you can see, the command you want to get a backing class is
ember generate component <component name> --component-class @glimmer/component. The short version of that would be
ember g component <component name> -gc.
Now, you might be wondering: why is the default to not generate a backing class? Since the launch of Ember Octane, Ember CLI defaults to generating “template-only” components because they’re the right starting point:
very often you don’t actually need a backing class: you can do everything you need to just by passing in arguments (including actions)
- template-only components have the best performance—the lowest memory usage and the fastest to render
- once you have a backing class, it’s a “state magnet”: it’s tempting to make components have their own local state whether or not that’s actually the best fit for your app’s data flow
- you can also always generate a backing class later by using the
ember generate component-class command!