在启动应用程序时传入angular度variables

我有我的客户端app.js在angular.js这个设置:

var options = {}; options.api = {}; options.api.base_url = "http://myDomainName.tld:8080"; 

我需要能够改变这在CLI上,当我正在build立我的应用程序。

我的想法是用咕噜声做这个。

任何其他的想法如何解决这个问题?

你可以使用grunt-template模块。

app.js文件添加为app.js.tpl

app.js.tpl

 var options = {}; options.api = {}; options.api.base_url = "<%= base_url %>"; 

Gruntfile.js

 module.exports = function(grunt) { grunt.initConfig({ 'template': { 'process-js-template': { 'options': { 'data': { 'base_url': 'http://myDomainName.tld:8080' //Can also use 'base_url': grunt.option('base_url') //If you wanted to take it from the CLI. //EG: grunt default --base_url=http://myDomainName.tld:8080 } }, 'files': { //The key being where you want to save the file. 'path/to/app.js': ['path/to/app.js.tpl'] } } } }); grunt.loadNpmTasks('grunt-template'); grunt.registerTask('default', [ 'template' ]); };