Skip to content

Instantly share code, notes, and snippets.

@MrNaif2018
Created December 16, 2019 13:47
Show Gist options
  • Save MrNaif2018/46a965929a9bcd0b150aaaa6703ccaa3 to your computer and use it in GitHub Desktop.
Save MrNaif2018/46a965929a9bcd0b150aaaa6703ccaa3 to your computer and use it in GitHub Desktop.
Dynamical loading of env variables in nuxt.js
export const state = () => ({
env: {}
})
export const mutations = {
setEnv (state, env) {
state.env = env
}
}
export const actions = {
nuxtServerInit ({ commit }) {
if (process.server) {
commit('setEnv', {
VAR1: process.env.ENV_VARIABLE_ONE,
VAR2: process.env.ENV_VARIABLE_TWO || 'default value'
})
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment