Skip to content
Tear your variables apart!
Branch: master
Clone or download

README.md

Separate env module - Tear your variables apart!

npm version npm downloads Circle CI Codecov Dependencies Standard JS

Separated environment variables for server and client build

📖 Release Notes

Setup

  1. Add the @nuxtjs/separate-env dependency with yarn or npm to your project
  2. Add @nuxtjs/separate-env to the modules section of nuxt.config.js:
  3. Configure it:
{
  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

  1. Clone this repository
  2. Install dependencies using yarn install or npm install
  3. Start development server using npm run dev

License

MIT License

Copyright (c) Alexander Lichter

You can’t perform that action at this time.