ionic-team / ionic-gulp-tasks

Collection of gulp tasks for building Ionic apps
41 stars 33 forks source link

added envify #26

Open mkuklis opened 8 years ago

mkuklis commented 8 years ago

Hi guys,

I ran into a situation where I needed to pass some env variables to the ionic build. This pull request adds support for envify. This should allow to pass variables from gulp like this:

gulp.task('build', ['clean'], function(done){
  runSequence(
    ['sass', 'html', 'fonts', 'scripts'],
    function(){
      buildBrowserify({
        minify: isRelease,
        browserifyOptions: {
          debug: !isRelease
        },
        uglifyOptions: {
          mangle: false
        },
        envifyOptions: { ENV: 'production' } 
      }).on('end', done);
    }
  );
});

and later access them with:

if (process.env.ENV == "production") {
 // do something
}

It looks like some other people asked about it too:

https://forum.ionicframework.com/t/debate-ionic-2-environment-development-variables-setup/44061