Sharing models via ember-cli addons?

Yes, this is absolutely something that addons are intended to help with.

Make an addon (easiest way is via ember addon my-product-models or some other way more imaginative name), and in that addon folder add a app/models/ folder that contains your shared models. Include that shared model addon with both applications (by adding it to package.json).

The files in app/ of the addon are merged with the ones in the applications app/ folder so that they end up at the same level in the module system.

Assuming that your addon had an app/models/foo.js file, and that you wanted to extend that from app/models/bar.js in your actual application you would do the following:

import Foo from './foo';

export default Foo.extend();
7 Likes