gulp-ng-constant
gulp-ng-constant copied to clipboard
Overriding Values?
Hi:
I would like to have a base set of config values, and then override only certain values in an environment-specific config. I'm having hard time figuring out how to get gulp-ng-constant to do that. Can you give me a hint.
Example: app.config.json would look like this: { "foo": "default", "bar": "default" } app.dev.json might look like this: { "foo":"dev" }
I want output to look like this .constant("foo", "dev") .constant("bar": "default")
I can't seem to make that work. (either app.dev.json completely overwrites app.config.json, so "bar" gets dropped, or app.config.json completely overwrites app.dev.json)
Hi, currently you can't override the constants from multiple configuration files only using gulp-ng-constant.
However, one solution would be to do the overriding outside the plugin and then pass the properties to it, similar to the multiple environments example
var gulp = require('gulp');
var ngConstant = require('gulp-ng-constant');
gulp.task('constants', function () {
var appConfig = require('./app.config.json');
var devConfig = require('./app.dev.config.json');
var finalConfig = Object.assign(appConfig, devConfig);
return ngConstant({
constants: finalConfig,
stream: true
})
.pipe(gulp.dest('dist'));
});
Please note that instead of passing this plugin into a pipe, you use the stream
option to create a stream from this plugin.
Let me know if this helps you
Thank you!
I actually ended up doing something very similar to what you described. I used lodash's merge function to override / merge my base config with the environment config.
On Thursday, September 29, 2016, Arturo Guzman [email protected] wrote:
Hi, currently you can't override the constants from multiple configuration files only using gulp-ng-constant.
However, one solution would be to do the overriding outside the plugin and then pass the properties to it, similar to the multiple environments example https://github.com/guzart/gulp-ng-constant#multiple-environments
var gulp = require('gulp');var ngConstant = require('gulp-ng-constant'); gulp.task('constants', function () { var appConfig = require('./app.config.json'); var devConfig = require('./app.dev.config.json'); var finalConfig = Object.assign(appConfig, devConfig); return ngConstant({ constants: finalConfig, stream: true }) .pipe(gulp.dest('dist')); });
Please note that instead of passing this plugin into a pipe, you use the stream option to create a stream from this plugin.
Let me know if this helps you
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/guzart/gulp-ng-constant/issues/41#issuecomment-250581732, or mute the thread https://github.com/notifications/unsubscribe-auth/ADmuZ4ejC1UJYpyFJbWGxCfTIp_W63Qzks5qvB9tgaJpZM4KJPuo .