Last active
August 31, 2017 00:18
Star
You must be signed in to star a gist
Handling environment variables in the browser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.ENV = { | |
TYPE: 'dev' | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
</head> | |
<body> | |
<script src="environment.min.js"></script> | |
<script> | |
// Third party code that uses | |
// environment variables. | |
</script> | |
</body> | |
<html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.ENV = { | |
TYPE: 'prod' | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment