简体   繁体   中英

Ember config file after build

I want to take some config properties from a config file instead from index.html(not from the meta generated from config/environment), for example myConfig.js with two variables (lang and host) that can be changed after build. Currently I put that variables in config/enviroment, but i want to separate this variables from this data.

For example:

index.html:

<!DOCTYPE html>
   ...
   <meta name="myapp/config/environment" content="%7B%22modulePrefix%22%3A%22user%22%2C%22environment%22%3A%22development%22%2C%22baseURL%22%3A%22/%22%2C%22locationType%22%3A%22auto%22%2C%22contentSecurityPolicy%22%3A%7B%22default-src%22%3A%22%27none%27%20localhost%22%2C%22script-src%22%3A%22%27self%27%20%27exportApplicationGlobal%22%3Atrue%7D">
   ...
   <script src="myconfig.js" ></script>
   ...
</html>

myconfig.js:

module.exports = function() {

   var MYCONFIG = {
       lang: 'en',
       host: 'http://.....'
   }

   return MYCONFIG ;
};

How this can be done?

Any help will be greatly appriciated

You can create a config utils

// utils/config-utils.js
export default {
 lang: 'en',
 host: 'http://.....'
}; 

and then import it where you need:

// controllers/my-controller.js
import ConfigUtil from '../utils/config';

const {
 lang
} = ConfigUtil;

export default MyController.extend({
   ...
});

最后,我将一个json文件放在公共文件夹中,并在应用程序路由中使用Ember。$。ajax来获取它。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM