Skip to content

Instantly share code, notes, and snippets.

@rafaelcamargo
Last active August 31, 2017 00:18
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save rafaelcamargo/f916d0d9e76d66848a16c236453594c2 to your computer and use it in GitHub Desktop.
Handling environment variables in the browser
window.ENV = {
TYPE: 'dev'
};
const argv = require('yargs').argv,
uglify = require('gulp-uglify'),
gutil = require('gulp-util'),
rename = require('gulp-rename');
gulp.task('env', function() {
const env = argv.env || 'dev';
return gulp.src(`./${env}.js`)
.pipe(uglify({mangle: false}).on('error', gutil.log))
.pipe(rename('environment.min.js'))
.pipe(gulp.dest('path/to/dist'));
});
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<script src="environment.min.js"></script>
<script>
// Third party code that uses
// environment variables.
</script>
</body>
<html>
window.ENV = {
TYPE: 'prod'
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment