https://github.com/nuxt-community/separate-env-module
Tear your variables apart!
https://github.com/nuxt-community/separate-env-module
environment nuxt nuxt-module nuxtjs separate
Last synced: about 1 year ago
JSON representation
Tear your variables apart!
- Host: GitHub
- URL: https://github.com/nuxt-community/separate-env-module
- Owner: nuxt-community
- License: mit
- Created: 2018-10-13T15:01:19.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2025-03-18T13:46:52.000Z (over 1 year ago)
- Last Synced: 2025-03-30T01:08:30.143Z (about 1 year ago)
- Topics: environment, nuxt, nuxt-module, nuxtjs, separate
- Language: JavaScript
- Size: 1.08 MB
- Stars: 56
- Watchers: 4
- Forks: 4
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Separate env module - Tear your variables apart!
[![npm version][npm-version-src]][npm-version-href]
[![npm downloads][npm-downloads-src]][npm-downloads-href]
[![Circle CI][circle-ci-src]][circle-ci-href]
[![Codecov][codecov-src]][codecov-href]
[![License][license-src]][license-href]
> Separated environment variables for `server` and `client` build
[📖 **Release Notes**](./CHANGELOG.md)
:warning: With Nuxt v2.13 you might want to use the [new runtime config](https://nuxtjs.org/blog/moving-from-nuxtjs-dotenv-to-runtime-config) instead of this.
## Setup
1. Add `@nuxtjs/separate-env` dependency to your project
```bash
yarn add @nuxtjs/separate-env # or npm install @nuxtjs/separate-env
```
2. Add `@nuxtjs/separate-env` to the `modules` section of `nuxt.config.js`
```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:
```js
{
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](./LICENSE)
Copyright (c) - Nuxt Community
[npm-version-src]: https://img.shields.io/npm/v/@nuxtjs/separate-env/latest.svg?style=flat-square
[npm-version-href]: https://npmjs.com/package/@nuxtjs/separate-env
[npm-downloads-src]: https://img.shields.io/npm/dt/@nuxtjs/separate-env.svg?style=flat-square
[npm-downloads-href]: https://npmjs.com/package/@nuxtjs/separate-env
[circle-ci-src]: https://img.shields.io/circleci/project/github/nuxt-community/separate-env-module.svg?style=flat-square
[circle-ci-href]: https://circleci.com/gh/nuxt-community/separate-env-module
[codecov-src]: https://img.shields.io/codecov/c/github/nuxt-community/separate-env-module.svg?style=flat-square
[codecov-href]: https://codecov.io/gh/nuxt-community/separate-env-module
[license-src]: https://img.shields.io/npm/l/@nuxtjs/separate-env.svg?style=flat-square
[license-href]: https://npmjs.com/package/@nuxtjs/separate-env