Skip to content

Commit

Permalink
docs(compile route templates): add a section to the faq about providi…
Browse files Browse the repository at this point in the history
…ng route templates with a v1 addon
  • Loading branch information
BlueCutOfficial committed Apr 10, 2024
1 parent 566925f commit cfd6de2
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions docs/v2-faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,29 @@ Additionally, there is a feature supported in node.js and modern bundlers to def
When using `package.json#exports` make sure that:
- the `addon.publicEntrypoints(...)` plugin in `rollup.config.mjs` includes _at least_ whatever is defined in `package.json#exports`
- the modules that `addon.appReexports(...)` exposes must have overlap with the `package.json#exports` so that the app-tree merging may import from the addon

### How can I provide route templates with my v2 addon?

During a v2 addon build step, standalone `.hbs` are considered template-only components by default.

If you want your v2 addon to provide a route template, the best way to proceed is to make it a `.gjs` file using [ember-route-template](https://github.com/discourse/ember-route-template). Similarly, if you want to migrate to v2 a classic addon that used to provide `.hbs` route templates, you should refactor the `.hbs` to `.gjs` files to complete the migration.

If for whatever reason the `.gjs` approach cannot be used, it's still possible to have your v2 addon providing the route templates as `.hbs`, but it requires extra configuration. During the build step, Rollup and Babel work together to transform all standalone `.hbs` into template-only components. Therefore, you need to tell both Rollup and Babel to _not_ compile a given list of `.hbs` files this way.

Let's assume your addon has a `templates/` folder that contains all your route templates. The files in `templates/` should be compiled as simple templates (not template-only components).

In the `rollup.config.mjs`, pass a list of glob patterns in the `excludeColocation` option of the function `addon.hbs`:

```js
addon.hbs({ excludeColocation: ['templates/**/*'] }),
```

In the `babel.config.json`, pass the same list of glob patterns in the `exclude` option of the `template-colocation-plugin`:

```
"plugins": [
["@embroider/addon-dev/template-colocation-plugin", {
exclude: ['templates/**/*']
}],
],
```

0 comments on commit cfd6de2

Please sign in to comment.