管理环境变量angularjs离子应用程序

时间:2015-05-19 09:17:49

标签: angularjs gruntjs gulp ionic

我希望能够为我的离子应用设置我的差异环境设置不同的网址

在我的gulpfile.js中,我已经包含了

gulpfile.js

var gulp = require('gulp');
var gutil = require('gulp-util');
var replace = require('gulp-replace-task'); 
var args    = require('yargs').argv; 
var bower = require('bower');
var concat = require('gulp-concat');
var sass = require('gulp-sass');
var minifyCss = require('gulp-minify-css');
var rename = require('gulp-rename');
var sh = require('shelljs');
var preprocess = require('gulp-preprocess');
    gulp.task('dev', function() {
      gulp.src('./js/appSettings.js')
        .pipe(preprocess({context: { NODE_ENV: 'DEVELOPMENT', DEBUG: true}}))
        .pipe(gulp.dest('./www/js/'));
    });

    gulp.task('test_env', function() {
      gulp.src('./js/appSettings.js')
        .pipe(preprocess({context: { NODE_ENV: 'TEST', DEBUG: true}}))
        .pipe(gulp.dest('./www/js/'));
    });

    gulp.task('prod', function() {
      gulp.src('./js/appSettings.js')
        .pipe(preprocess({context: { NODE_ENV: 'PRODUCTION'}}))
        .pipe(gulp.dest('./www/js/'));
    });

我创建了一个新文件www / js / appSettings.js

AppSettings = {
  // @if ENV == 'DEVELOPMENT'
  baseApiUrl: 'http://10.0.3.2:3000/',
  debug: true
  // @endif
  // @if ENV == 'TEST'
  baseApiUrl: 'stg-partners.loanstreet.com.my/'
  // @endif
  // @if ENV == 'PRODUCTION'
  baseApiUrl: 'https://api-example.com/'
  // @endif
}

在我的services.js

.factory('referralCasesGroupByCaseStatus', function($http, $q) {
  var getcaseStatusByCount = {
    caseStatusCount: function(paramsData){
      var d= $q.defer();

      var url = AppSettings.baseApiUrl + '/api/v1/case_status_count?callback=JSON_CALLBACK&username='+paramsData+'&format=json';
      $http.post(url).then(function(data) {
        if(data.status===200){
          d.resolve(data.data);
        }
        else {
          d.reject(data);
        }
      });
      return d.promise;  
    }
  return getcaseStatusByCount;
})

我正在关注本教程http://jbavari.github.io/blog/2014/08/23/managing-environment-variables-for-your-ionic-application/

在教程中,设置与常规离子应用程序略有不同。就像我真的不明白应该在这里gulp.src('./js/appSettings.js')

我的appSettings.js文件的目录是projectname / www / js / appSettings.js

我有什么遗漏或做错了吗?

0 个答案:

没有答案