Dmi*_*tro 0 ember.js ember-cli
中有开发、测试和生产环境Ember CLI。我有测试和生产服务器。我需要像在生产环境中一样在测试服务器上进行构建,但使用另一个环境配置。但 test envEmber CLI用于自动测试。
我尝试使用文件ember build --environment development中的下一个选项调用测试服务器ember-cli-build.js:
var app = new EmberApp(defaults, {
// Add options here
fingerprint: {
prepend: 'https://s-test.mycdn.com/',
enabled: true
}
});
Run Code Online (Sandbox Code Playgroud)
但我得到了错误:
The Broccoli Plugin: [AssetRewrite] failed with:
TypeError: Cannot read property '2' of null
.....
The broccoli plugin was instantiated at:
.....
Run Code Online (Sandbox Code Playgroud)
在测试服务器上构建 ember 应用程序的正确方法是什么?
这可能会令人困惑,但您想要的不是环境。您想要部署目标。这是一篇关于两者之间差异的精彩博客文章:不要混淆部署目标的环境(该 URL 已在 deveo.com 的重组/接管中被丢弃,但archive.org 上存在快照)。
在 Ember 中,环境是关于如何缩小你的代码、如何对你的资产进行指纹识别、启用/禁用某些调试功能等。它们与你想要在哪里部署代码、你想要使用哪个 API URL 或类似的东西无关。
您可能碰巧有名为test或 的服务器development,但是在部署到这些服务器时,您应该始终将环境设置为production,而不是test或development。
为了支持多个服务器(部署目标),我将使用环境变量来做到这一点。就像是:
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
Run Code Online (Sandbox Code Playgroud)
在您的 中ember-cli-deploy.js,您只需通过 访问该值process.env.DEPLOY_TARGET,如下所示:
const deployTarget = process.env.DEPLOY_TARGET;
if (deployTarget === 'development') {
// ...
} else if (deployTarget === 'test') {
// ...
} else if (deployTarget === 'staging') {
// ...
} else if (deployTarget === 'production') {
// ...
}
Run Code Online (Sandbox Code Playgroud)
我建议使用ember-cli-deploy插件来自动化此过程,以便您只需键入即可ember deploy staging创建构建staging并部署它。
| 归档时间: |
|
| 查看次数: |
1318 次 |
| 最近记录: |