Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use specific files for different enviroments #134

Closed
cmolina opened this issue Aug 22, 2016 · 6 comments
Closed

Use specific files for different enviroments #134

cmolina opened this issue Aug 22, 2016 · 6 comments

Comments

@cmolina
Copy link
Contributor

cmolina commented Aug 22, 2016

It would be awesome to have files for each environment (development, production, qa, etc) available on /config, and to copy them just before running the server/compiling.
I am thinking on using different config.xml, and also a static class storing API's urls.

@lathonez
Copy link
Owner

Totally agree. There must be some guidance out there from Ionic (or Angular2) about the best way of doing this?

The guys at angular2-seed are using different build tasks in gulp per environment (which would take care of the copying for you, I guess). I don't have time to dig into it right now.

https://github.com/mgechev/angular2-seed/blob/master/gulpfile.ts#L13-L67

It's really a question for the Ionic guys, they need to recommend a way for this to be done.

@cmolina
Copy link
Contributor Author

cmolina commented Aug 23, 2016

My first attempt was to make an cordova hook -but we need to run the task before gulp scripts.

So I added this new task

gulp.task('enviroment', function(){
  var env = process.env.ENV || 'dev';
  var options = {
    src: 'config/' + env + '/**/*.*',
    dest: './',
    onComplete: function() {
      console.log('All env files were copied.');
    },
    onError: function(err) {
      console.error(err.toString());
      this.emit('end');
    }
  }

  return gulp.src(options.src)
    .pipe(gulp.dest(options.dest))
    .on('end', options.onComplete)
    .on('error', options.onError);
});

and I added as a dependency to script.

gulp.task('scripts', ['enviroment'], copyScripts);

So now, to make a build for android in the QA enviroment, you need to run ENV=qa ionic build android. What do you think?

@lathonez
Copy link
Owner

Looks good, I think the solution has to be a gulp script at the moment.

I keep being reminded (#131, #38 (comment)) that Ionic are moving back to webpack. Not sure what the setup is going to be after that with regard to gulp, but having environment specific config files and [insert task runner here] copying them at build time is the way to go.

Incidentally, our closed source project will be going to prod within the next couple of weeks, so we'll need to address this ourselves.

If we deviate from the pattern above I'll be sure to raise here for discussion.

For now I'd like to close this (I'll add a link from the blog post). Is that OK with you or is there something else to cover?

@cmolina cmolina mentioned this issue Aug 23, 2016
@lathonez
Copy link
Owner

Ah I hadn't thought of doing a PR! It's 'cause I don't see myself as having ownership of Ionic's gulpfile (I rarely touch it, if ever).

I do think it's a good idea to have this as an example though.

@lathonez
Copy link
Owner

lathonez commented Sep 1, 2016

#135 closed

@lathonez lathonez closed this as completed Sep 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants