A public service announcement for addon authors:
First-class component templates is a merged RFC and already has a working implementation. Users are going to want to consume your components from this new style of templates.
Mostly that will Just Work, but there are a few things you may not have considered.
-
Use component template co-location. This isn’t just nice for developer ergonomics – it makes components work as first-class values. Without it, your component can’t be passed around as a value in Javascript without losing its template.
The older pattern of setting
layouton an@ember/componentalso works correctly as a first-class value, since it carries its template within it. But this only works on the older style Ember components, not Octane-style Glimmer components, which is why I suggest co-location for all components of either kind.The case that does not work is separately providing
app/components/thing.jsandapp/templates/components/thing.hbsfrom your addon. For an example of fixing this pattern, see Co-locate component templates by ef4 · Pull Request #661 · cibernox/ember-basic-dropdown · GitHub. -
Make sure the components (and helpers and modifiers) in your
/addonfolder have reasonable filenames, because those are going to be what people import from to use them.It used to really not matter how you organized these, because only the reexports in the
/appfolder governed what consumers of your addon would have access to. But we’re moving toward not needing/appfolder merging anymore. Think of your addon more as a normal NPM library whose modules will be available to consuming packages.If you would like strong control over which modules in your package are public API and which are private, consider adopting V2 addon format and using the
exportskey in package.json to control it explicitly. V2 addons fully support that feature, V1 (traditional) addons do not.While you are free to organize your files within
/addonhowever you want and it will work, it’s still a good idea to stick to the convention ofyour-addon/components/thingbeing the import path for theThingcomponent fromyour-addon, because it’s predictable.While it’s possible to export or reexport many components from a single file, this will defeat certain optimizations as we move toward a world where browsers natively load ES modules. They will load whole modules, so if users are likely to only want some of your components, you should put those components into separate ES modules.
First-class templates plus Glint is looking really nice. If you haven’t had a chance to play with it give it a go.