Comparing version 0.1.1 to 0.2.0
@@ -19,3 +19,3 @@ { | ||
}, | ||
"version": "0.1.1" | ||
"version": "0.2.0" | ||
} |
@@ -19,2 +19,10 @@ # vue-env | ||
A secondary parameter can be set right away also for environment specific config. | ||
~~~ | ||
import _env from './env.js'; | ||
Vue.use(require('vue-env'), _env, require('./config/' + _env.APP_ENV + '.js')); | ||
~~~ | ||
After that just use the `get()` method to fetch environment constants. | ||
@@ -25,2 +33,5 @@ | ||
this.$env.get('SOME_ENV_VAR', 'default value'); | ||
this.$env.set('key', 'val'); | ||
this.$env.set({key: 'val', key2: 'val2'}); | ||
~~~ | ||
@@ -41,4 +52,5 @@ | ||
## Note | ||
As a side note, it's generally not a good idea to commit the `env.js` file. It's best to keep an `example.env.js` file that is committed instead. |
@@ -1,28 +0,47 @@ | ||
/* | ||
https://github.com/websanova/vue-env | ||
rob@websanova.com | ||
Version 0.1.1 | ||
*/ | ||
module.exports = (function () { | ||
function Env(params) { | ||
if ( ! params) { | ||
try { | ||
params = require('../../env.js'); | ||
function _set(params, key, val) { | ||
var i; | ||
if ( ! key) { return; } | ||
params = params || {}; | ||
if (typeof key === 'object') { | ||
for (i in key) { | ||
params[i] = key[i]; | ||
} | ||
} | ||
catch(e) { | ||
params = {}; | ||
else { | ||
params[key] = val; | ||
} | ||
return params; | ||
} | ||
this.params = params; | ||
} | ||
function Env(env, conf) { | ||
if ( ! env) { | ||
try { | ||
env = require('../../env.js'); | ||
} | ||
catch(e) { | ||
env = {}; | ||
} | ||
} | ||
Env.prototype.get = function (key, def) { | ||
return this.params[key] || def; | ||
} | ||
this.params = _set(env, conf); | ||
} | ||
function install(Vue, params) { | ||
Vue.prototype.$env = new Env(params); | ||
} | ||
Env.prototype.get = function (key, def) { | ||
return this.params[key] || def; | ||
}; | ||
module.exports = install; | ||
Env.prototype.set = function (key, val) { | ||
this.params = _set(this.params, key, val); | ||
}; | ||
return function install(Vue, env, conf) { | ||
Vue.prototype.$env = new Env(env, conf); | ||
} | ||
})(); |
2581
35
53