Can I use main.dev.ts file ? Please :/


#1

Hey Is it possible to use the main.dev.ts file to store variables ?
I’m not sure how I will be able to do it , but it makes sense to have it there.
e.g. this in main.dev.ts
DEV_URL = 'foo/api/v1/test';

and main.prod.ts
DEV_URL = 'foo/api/v1/production';

and how can this be referenced on other pages/providers ?


#2

I solved such a question like following:

I created my own class resources.ts which export following:

export class Resources {

   static get Constants():any {
       return {
        API: {
            DEV_URL = 'foo/api/v1/test';
       }
     }
  }

}

which you could use

 Resources.Constants.API.DEV_URL

To switch between TEST_URL and PROD_URL I have then write a gulp task to switch between these (like “gulp prod” and “gulp test”)

Of course it need a little bit of attention to be sure to never validate in my repository my class with the test URL…but otherwise that made the trick for me.


#3

Hey @reedrichards , great idea :slight_smile: ,
I’m just a little disappointed that there is no documentation on using main.dev.ts and main.prod.ts


#4

Maybe there is something side angular2?
Anyway glad to hear you like the idea

About gulp, I use:

npm install --save-dev replace

and something like

var replaceFilesTargetServer = ['./src/providers/resources.ts'];

gulp.task('test', function () {
  return replace({
    regex: "https://produrl",
    replacement: "http://devurl",
    paths: replaceFilesTargetServer,
    recursive: false,
    silent: false
  });
});