多个“应用程序"使用 ember-cli [英] Multiple "apps" with ember-cli

查看:13
本文介绍了多个“应用程序"使用 ember-cli的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从一些旧的本土构建工具迁移到 ember-cli.我们的应用非常大,实际上分为几个共享一组通用工具和组件的 ember.js 单页应用(例如索引、管理、报告等).

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.

我想弄清楚 ember-cli 是否可以实现,如果可以,我该怎么做?我看到一些人在谈论 pod,其他人在谈论插件,还有另一组人在谈论私人凉亭存储库.我试图找出每一个的信息,但似乎一切都在不断变化.

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.

编辑(2015 年 1 月 28 日):

Ember-cli 插件现在更稳定,可用于此应用程序.但恕我直言,他们对于这个用例仍然有一些缺点.它们创建了更多样板,因为您仍然需要将单个模型/控制器/组件/等导入您的应用程序空间.请参阅此处插件下的组件"部分:http://www.ember-cli.com/#managing-插件依赖

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

还有一个有趣的 RFC 可以为 ember 和 ember-cli 提供类似引擎的支持,也可以满足这一点:https://github.com/emberjs/rfcs/pull/10

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

编辑(2015 年 10 月 3 日):

引擎 RFC 有一个新的更新,这对许多用户来说看起来很有希望.但是,我们仍然需要多个实际上不同的应用程序.与我一起工作的另一位开发人员花了一些时间来详细说明如何最好地使用这种模式.

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.

我已经记录并在 repo 中创建了演示:https://github.com/workmanw/ember-multi-应用

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

推荐答案

Ember-cli 不支持多个开箱即用的应用程序.(顺便说一句,我仍然很惊讶 SproutCore 中有多少常见的东西在 Ember 中仍然存在问题).豆荚 您提到的 ember-cli 依赖的工具支持,因此大多数 ember-cli 命令都可以正常工作.its 中描述了解析器(一个 ember-cli 依赖项)将所有内容放在一起的方式拉取请求.但是您将无法使用生成器,因为它们还不知道 Pod.Ember 插件主要扩展 ember-cli 或 Ember 本身,虽然它们可能能够解决您的问题,但它们不是正确的工具.

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.

我认为对你来说最好的事情是等待更多的 pods 感知 ember-cli 命令或者自己实现这个功能到 ember-cli.

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.

接下来最好的做法是将您的项目实际拆分为多个项目,每个应用一个,并通过 Bower、NPM 或其他解决方案包含共享代码.如果您有自己的私有组件,它们通常都允许通过 git 或文件系统导入依赖项.你可能有一个超级项目,所有东西都放在一起(通过 NPM 或 Git 子模块) 并且您仍然可以使用一些自行开发的解决方案来协调所有内容(基本上将其委托给 ember-cli).

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).

这篇关于多个“应用程序"使用 ember-cli的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆