永远使用Ember-CLI [英] Use Forever with Ember-CLI

查看:948
本文介绍了永远使用Ember-CLI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用Ember-CLI建立了一个网站,现在已经准备好进行生产了,所以我们正在寻找一种永久性的运行方式。



现在我们正在使用$ ember serve --port 80



但显然这只能在我们我已经使用Forever,以保持一个节点应用程序运行,但不知道如何使用Ember CLI进行工作,因为ember服务命令显然不仅仅是运行app.js吗?



任何输入将不胜感激!

解决方案

Ember-CLI应用程序不是节点应用程序,他们是浏览器应用程序,所以你不需要任何特别的服务。要保持和Ember-CLI应用程序永久运行,我建议:

  ember build --environment = production 

这将执行必要的构建步骤,以便代码在浏览器中运行(例如,传播ES6模块),并将代码放入构建文件夹。它还将缩小JS文件和指纹所有资源(仅在环境生产时才会发生)。



然后将所有文件放在 dist / 文件夹在Web服务器上。



我建议Apache或Nginx,但任何事情都可以工作。 b
$ b

修改



正如Omair Vaiyani指出的,这可能在某些服务器上无效,因为Ember-CLI
使用的是locationType:'auto',默认为'history'。为了使其正常工作,您必须将SERVER配置为从所有路由提供的Ember应用程序。



我做什么,服务器很好,因为我无法控制服务器,只是将locationType更改为哈希,这将生成URL哈希( http:// myemberapp /#/ myroute / myid ),并且可以与任何服务器一起工作。只需编辑environment.js文件:

  module.exports = function(environment){
var ENV = {
/ * other stuf ... * /
locationType:'hash',
/ * other stuf ... * /
},
/ *其他东西* /

```


I've set up a website using Ember-CLI and it is now ready for production, so we're looking for a way to keep it running permanently.

Right now we're using $ ember serve --port 80

but obviously this only works whilst we're logged in. I've used Forever before to keep a node app running but am not sure how to make this work with Ember CLI, as the 'ember serve' command obviously does more than just running app.js?

Any input would be appreciated!

解决方案

Ember-CLI apps are NOT node apps, they are Browser apps, so you don't need anything special to serve them. To keep and Ember-CLI app running permanently, I suggest doing:

ember build --environment=production

This will perform the necessary build steps so that the code works in browsers (e.g, transpiling ES6 modules) and put the code in the build folder. It will also minify JS files and fingerprint all resources (this only happens when the environment is production).

All you have to to then is put the files inside the dist/ folder on a Web Server.

I suggest Apache or Nginx, but anything will work.

Edit

As Omair Vaiyani pointed out, this might not work in some servers because Ember-CLI uses the locationType: 'auto' which defaults to 'history'. For that to work, you have to configure your SERVER to serve the ember app from all routes.

What I do, and server me well because I don't have control over the server, is to simply change the locationType to 'hash', which will generate URLs with hashes (http://myemberapp/#/myroute/myid) and will work with any server. Just edit the environment.js file accordingly:

module.exports = function(environment) {
   var ENV = {
      /* other stuf ... */
      locationType: 'hash',
      /* other stuf ... */
   },
   /* other stuff */

```

这篇关于永远使用Ember-CLI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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