To use this task, export MYAPP_ENV=development
and call gulp env
Last active
January 22, 2016 17:49
-
-
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)
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
{ | |
"name": "myApp" | |
"api_url": "/api/v1", | |
"cache": true, | |
"http_headers": { | |
"Authorization": "Bearer 8675309" | |
} | |
} |
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
angular.module('<%= name %>', []).constant("AppConfig", { | |
"api_url": "<%= api_url %>", | |
"cache": <%= cache %>, | |
"http_headers": <%= JSON.stringify(http_headers) %> | |
}); |
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
'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