Skip to content

Instantly share code, notes, and snippets.

@toadkicker
Last active January 22, 2016 17:49
Show Gist options
  • Save toadkicker/7027d8fc0187c4540f7a to your computer and use it in GitHub Desktop.
Save toadkicker/7027d8fc0187c4540f7a to your computer and use it in GitHub Desktop.
Environment specific configurations with Gulp for Angular JS (but any old js framework can use this)

To use this task, export MYAPP_ENV=development and call gulp env

{
"name": "myApp"
"api_url": "/api/v1",
"cache": true,
"http_headers": {
"Authorization": "Bearer 8675309"
}
}
angular.module('<%= name %>', []).constant("AppConfig", {
"api_url": "<%= api_url %>",
"cache": <%= cache %>,
"http_headers": <%= JSON.stringify(http_headers) %>
});
'use strict';
var gulp = require('gulp'),
rename = require('gulp-rename'),
path = require('path'),
template = require('gulp-template');
var ENV = process.env.MYAPP_ENV || "development";
var config = require(path.join(__dirname, "config", "environments", ENV+".json"));
gulp.task('env', function () {
return gulp.src('config/environments.ejs')
.pipe(template(config))
.pipe(rename({basename: 'config', extname: '.js'}))
.pipe(gulp.dest('app/components'));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment