Separated environment variables for
serverandclientbuild
- Add
@nuxtjs/separate-envdependency to your project
yarn add @nuxtjs/separate-env # or npm install @nuxtjs/separate-env- Add
@nuxtjs/separate-envto themodulessection ofnuxt.config.js
{
modules: [
'@nuxtjs/separate-env'
],
env: {
// Your environment variables here (see Configuration section below)
}
}To define environment variables only available on server/client side,
use the env key of your nuxt.config.js and nest the variables
in a server or client object:
{
env: {
server: {
ONLY_SERVER: 'yup',
DIFFERENT_ON_BOTH: 'server'
},
client: {
ONLY_CLIENT: 'okay',
DIFFERENT_ON_BOTH: 'client'
},
normalEnvVariableThatWillBeAvailableEverywhere: 'Hi'
}
}That's it! You are good to go.
IMPORTANT: Be aware that server-side means on every first render of your application.
Your secret tokens won't be included anywhere except where you use them
- Clone this repository
- Install dependencies using
yarn installornpm install - Start development server using
npm run dev
Copyright (c) - Nuxt Community