Created
December 16, 2019 13:47
-
-
Save MrNaif2018/46a965929a9bcd0b150aaaa6703ccaa3 to your computer and use it in GitHub Desktop.
Dynamical loading of env variables in nuxt.js
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
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