separate-env-module
separate-env-module copied to clipboard
Tear your variables apart!
Separate env module - Tear your variables apart!
Separated environment variables for
serverandclientbuild
📖 Release Notes
:warning: With Nuxt v2.13 you might want to use the new runtime config instead of this.
Setup
- 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)
}
}
Configuration
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.
Caveats
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
Development
- Clone this repository
- Install dependencies using
yarn installornpm install - Start development server using
npm run dev
License
MIT License
Copyright (c) - Nuxt Community