Home
Softono
separate-env-module

separate-env-module

Open source MIT JavaScript
57
Stars
4
Forks
13
Issues
2
Watchers
1 year
Last Commit

About separate-env-module

Tear your variables apart!

Platforms

Web Self-hosted

Languages

JavaScript

Links

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

:warning: With Nuxt v2.13 you might want to use the new runtime config instead of this.

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