如何为Ember-CLI建立过渡环境? [英] How to make staging environment for Ember-CLI?

查看:90
本文介绍了如何为Ember-CLI建立过渡环境?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Ember CLI 中有开发,测试和生产环境。
我有测试和生产服务器。我需要像在生产环境上那样在测试服务器上进行构建,但要使用另一个环境配置。但是在 Ember CLI 中测试环境,用于自动测试。

There are development, test and production environments in Ember CLI. I have test and production server. And I need to make build on test server like on production but with another environment configs. But test env in Ember CLI used for automatic tests.

我试图在测试服务器上调用 ember build --environment development ,并在 ember-cli-build.js 文件:

I tried to call ember build --environment development on test server with next options in ember-cli-build.js file:

var app = new EmberApp(defaults, {
   // Add options here
   fingerprint: {
     prepend: 'https://s-test.mycdn.com/',
     enabled: true
   }
});

但是我得到了错误:

The Broccoli Plugin: [AssetRewrite] failed with:
TypeError: Cannot read property '2' of null
.....
The broccoli plugin was instantiated at:
.....

在测试中构建余烬应用程序的正确方法是什么服务器?

What is right way to build ember application on test server?

推荐答案

这可能令人困惑,但您想要的是环境。您要部署目标。这是一篇很棒的博客文章,介绍了两者之间的区别:不要混淆部署目标的环境(该URL已在deveo.com的reorg / takeover中被丢弃,但快照在archive.org上存在)。

This might be confusing, but what you want is not environments. You want deploy targets. Here's a great blog post about difference between the two: Do not confuse environment for deploy target (that URL has been trashed in a reorg/takeover of deveo.com but a snapshot exists on archive.org).

在Ember中,环境与代码的缩减方式,资产的指纹,启用/禁用某些调试功能等有关。它们并非关于要在何处部署代码,所需的API URL。

In Ember, environments are about how your code is minified, your assets are fingerprinted, enabling/disabling certain debugging features, etc. They are not about where you want to deploy your code, which API URL you want to use, or anything like that.

您可能碰巧拥有名为 test development的服务器,但是在部署到这些服务器时,应始终将环境设置为生产,而不是 test 开发

You might happen to have servers called test or development, but when deploying to these servers, you should always set environment to production, not test or development.

为了支持多个服务器(部署目标),我将使用env vars来做到这一点。像这样的东西:

In order to support multiple servers (deploy targets), I would use env vars to do that. Something like:

DEPLOY_TARGET=development ember build --environment=production
DEPLOY_TARGET=test ember build --environment=production
DEPLOY_TARGET=staging ember build --environment=production
DEPLOY_TARGET=production ember build --environment=production

ember-cli-deploy.js 中,您只需通过 process.env.DEPLOY_TARGET 访问该值,例如

And in your ember-cli-deploy.js, you simply access the value through process.env.DEPLOY_TARGET, like this:

const deployTarget = process.env.DEPLOY_TARGET;
if (deployTarget === 'development') {
  // ...
} else if (deployTarget === 'test') {
  // ...
} else if (deployTarget === 'staging') {
  // ...
} else if (deployTarget === 'production') {
  // ...
}

我建议使用 ember-cli-deploy 插件可自动执行此过程,因此您只需键入 ember部署登台即可创建登台的构建并部署它。

I recommend using ember-cli-deploy addon to automate this process, so that you could just type ember deploy staging to create a build for staging and deploy it.

这篇关于如何为Ember-CLI建立过渡环境?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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