Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
328 views
in Technique[技术] by (71.8m points)

ember.js - Multiple "apps" with ember-cli

I'm trying to migrate to ember-cli from some old homegrown build tools. Our app is quite large and is actually split into several ember.js single page apps (e.g. index, admin, reports, etc) that share a common set of utils and components.

I'm trying to figure out if that's even possible with ember-cli and if so, how do I do it? I saw some people talking about pods, others talking about addons and yet another set of people talking about private bower repos. I tried finding out information on each of these, but it seems it's all in a bit of flux.

I'm not picky about the directory structure or the details. But I guess this is how I would envision it:

[app]
  - [controllers]
  - [models]
  - [routes]
  - [views]
  - index.html
[admin]
  - [controllers]
  - [models]
  - [routes]
  - [views]
  - index.html
[reports]
  - [controllers]
  - [models]
  - [routes]
  - [views]
  - index.html
[shared_code]
  - [components]
  - [utils]
Brocfile.js
etc

Any advice would be greatly appreciated. Even just a starting point would be immensely helpful.


Edit (Jan 28th 2015):

Ember-cli addons are more stable now and could be used for this application. But IMHO they still have some short comings for this use case. They create more boiler plate as you still have to import individual models/controllers/components/etc into your application space. See the "Components" section under the addons here: http://www.ember-cli.com/#managing-addon-dependencies

There is also an interesting RFC to bring engine like support to ember and ember-cli that could satisfy this as well: https://github.com/emberjs/rfcs/pull/10


Edit (October 3rd 2015):

There is a new update to the Engines RFC and that looks promising for many users. However, we still have the need for multiple apps which are actually different. Another developer I work with spent sometime to flush out the details of how best to use this pattern.

I've documented that and created demo in a repo: https://github.com/workmanw/ember-multi-app

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Ember-cli doesn’t support multiple apps out of the box. (By the way, I am still amazed how many things that were common in SproutCore are still problematic with Ember). The pods you mentioned are supported by tools which ember-cli depends on, so most of the ember-cli commands will work fine. The way resolver (an ember-cli dependency) puts everything together is described in its pull request. But you won’t be able to use generators because they are not aware of pods yet. Ember addons mostly extend ember-cli or Ember itself, although they may be able to solve your problem, they are not the right tool.

I think the best thing for you is to wait for more pods aware ember-cli commands or to implement this feature to ember-cli yourself.

The next best thing is to actually split your project into multiple projects, one per app, and include shared code via Bower, NPM or other solution. They all usually allow to import dependencies via git or file system if you have your own private components. You might have a super project where everything goes together (via NPM or Git submodules) and where you’d still have some homegrown solution to orchestrate everything (by basically delegating it to ember-cli).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...