Skip to content

nuxt-community/separate-env-module

This branch is 1 commit ahead of, 2 commits behind master.

Repository files navigation

Separate env module - Tear your variables apart!

npm version npm downloads Circle CI Codecov License

Separated environment variables for server and client build

📖 Release Notes

Setup

  1. Add @nuxtjs/separate-env dependency to your project
yarn add @nuxtjs/separate-env # or npm install @nuxtjs/separate-env
  1. Add @nuxtjs/separate-env to the modules section of nuxt.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

  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) - Nuxt Community