Skip to content

Instantly share code, notes, and snippets.

@chris-ramon
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chris-ramon/fd797b752f720eea19e3 to your computer and use it in GitHub Desktop.
Save chris-ramon/fd797b752f720eea19e3 to your computer and use it in GitHub Desktop.
gulp replacer
angular.module('coolapp-constants',[])
.constant('apiUrl', '@@apiUrl');
// gulp-replace-task
//- config/
// ` localdev.json
// ` test.json
// ` production.json
// localdev.json
{
"apiUrl":"https://dev.coolapp.com/api"
}
// production.json
{
"apiUrl":"https://www.coolapp.com/api"
}
var gulp = require('gulp');
var replace = require('gulp-replace-task');
var args = require('yargs').argv;
var fs = require('fs');
gulp.task('replace', function () {
// Get the environment from the command line
var env = args.env || 'localdev';
// Read the settings from the right file
var filename = env + '.json';
var settings = JSON.parse(fs.readFileSync('./config/' + filename, 'utf8'));
// Replace each placeholder with the correct value for the variable.
gulp.src('js/coolapp-constants.js')
.pipe(replace({
patterns: [
{
match: 'apiUrl',
replacement: settings.apiUrl
}
]
}))
.pipe(gulp.dest('build/js'));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment