Closed cmolina closed 8 years ago
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.
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?
Looks good, I think the solution has to be a gulp script at the moment.
I keep being reminded (#131, https://github.com/lathonez/clicker/issues/38#issuecomment-239497285) 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?
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.
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 differentconfig.xml
, and also a static class storing API's urls.