[英]How to use global variables in Ember app, specifically in index.html?
I would like to directly modify the index.html of my Ember app using command line variables passed in. So I can set them under 'ENV' in my environment.js file, and then I can access them in some of my .js files by importing ENV. 我想使用传入的命令行变量直接修改Ember应用程序的index.html。因此,我可以在我的environment.js文件中的“ ENV”下设置它们,然后在一些.js文件中访问它们通过导入ENV。 However, in my index.html file, these variables don't show up even though the "rootURL" variable does.
但是,在我的index.html文件中,即使“ rootURL”变量出现了,这些变量也没有出现。 For example, if I set
rootURL: "/blah"
and var1: "/blah2"
in ENV, then if I have something like a href={{rootURL}}
and a href = {{var1}}
, then the first link works while the second doesn't. 例如,如果我在ENV中设置
rootURL: "/blah"
和var1: "/blah2"
,则如果我有类似a href={{rootURL}}
和a href = {{var1}}
,则第一个链接有效,而第二个无效。
So I'm assuming that {{rootURL}} doesn't come directly from the ENV variable, but I can't find where it comes from. 因此,我假设{{rootURL}}不是直接来自ENV变量,但是我找不到它来自哪里。 I was trying to do something similar with variables in my 'app.js' but I'm confused about this line:
import config from './config/environment';
我试图对'app.js'中的变量做类似的事情,但是我对这行感到困惑:
import config from './config/environment';
What exactly does this import? 这到底导入了什么? I can't find anything named "config" in environment.js.
我在environment.js中找不到任何名为“ config”的东西。 Is it possible to set global variables in that file (app.js)?
是否可以在该文件(app.js)中设置全局变量?
I'm using ember-cli-inline-content
to use variable in my index, so I can change some urls depending the environment (production or dev) for assets like that: 我正在使用
ember-cli-inline-content
在索引中使用变量,因此可以根据环境(生产或开发)来更改某些网址,例如:
<link rel="stylesheet" href="{{content-for 'ASSETS_BASE_URL'}}/xxx/yyy/assets/vendor.css">
in my ember-cli-build.js
file: 在我的
ember-cli-build.js
文件中:
if (app.env === 'development') {
app.options.inlineContent = {
ASSETS_BASE_URL: {
content: 'http://lvh.me:8080'
}
};
}
if (app.env === 'production') {
app.options.inlineContent = {
ASSETS_BASE_URL: {
content: 'https://assets.mydomain.com'
}
};
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.