All Projects → samtgarson → Nuxt Env

samtgarson / Nuxt Env

Inject env vars for your Nuxt app at runtime

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Nuxt Env

Laravel Nuxt
A Laravel-Nuxt starter kit.
Stars: ✭ 943 (+457.99%)
Mutual labels:  nuxt, ssr
Virapro.ru
[E-commerce] Plumbing Store
Stars: ✭ 45 (-73.37%)
Mutual labels:  nuxt, ssr
Nuxt Static Render
Nuxt module for SSR without rehydration payload
Stars: ✭ 32 (-81.07%)
Mutual labels:  nuxt, ssr
Hackernews
HackerNews clone built with Nuxt.js
Stars: ✭ 758 (+348.52%)
Mutual labels:  nuxt, ssr
Sails Nuxt
Sails + Nuxt + Vuetify Combo <3
Stars: ✭ 92 (-45.56%)
Mutual labels:  nuxt, ssr
Essay
A blog system based on Nuxt.js
Stars: ✭ 913 (+440.24%)
Mutual labels:  nuxt, ssr
Axios Module
Secure and easy axios integration with Nuxt.js
Stars: ✭ 998 (+490.53%)
Mutual labels:  nuxt, ssr
Sitemap Module
Sitemap Module for Nuxt
Stars: ✭ 539 (+218.93%)
Mutual labels:  nuxt, ssr
Vue Masonry Wall
A pure vue responsive masonry layout without direct dom manipulation and ssr support.
Stars: ✭ 79 (-53.25%)
Mutual labels:  nuxt, ssr
Laravel Vuejs.com
Laravel and VueJs Blog, using Laravel nova, GraphQL, NuxtJs, Apollo and ...more
Stars: ✭ 54 (-68.05%)
Mutual labels:  nuxt, ssr
Vuecnodejs
⚽️🎉Vue初/中级项目,CnodeJS社区重构。( a junior project of Vue.js, rewrite cnodejs.org ) 预览(DEMO):
Stars: ✭ 705 (+317.16%)
Mutual labels:  nuxt, ssr
Auth Module
auth.nuxtjs.org
Stars: ✭ 1,624 (+860.95%)
Mutual labels:  nuxt, ssr
Wemake Vue Template
Bleeding edge vue template focused on code quality and developer happiness.
Stars: ✭ 645 (+281.66%)
Mutual labels:  nuxt, ssr
Nuxt.js
The Intuitive Vue(2) Framework
Stars: ✭ 38,986 (+22968.64%)
Mutual labels:  nuxt, ssr
Awes Io
Awes.io // boilerplate based on Vue, Nuxt, TailwindCSS plus Laravel as a backend. 🤟
Stars: ✭ 599 (+254.44%)
Mutual labels:  nuxt, ssr
Veluxi Starter
Veluxi Vue.js Starter Project with Nuxt JS and Vuetify
Stars: ✭ 39 (-76.92%)
Mutual labels:  nuxt, ssr
Nuxt Firebase Sns Example
Nuxt v2 & Firebase(Hosting / Functions SSR / Firestore), Google Auth SNS Example.
Stars: ✭ 485 (+186.98%)
Mutual labels:  nuxt, ssr
Nuepress
📖 Nuxt.js + WordPress REST API
Stars: ✭ 524 (+210.06%)
Mutual labels:  nuxt, ssr
Hapi Nuxt
Nuxt.js plugin for Hapi.js
Stars: ✭ 46 (-72.78%)
Mutual labels:  nuxt, ssr
Naice Blog
😺 新的博客上线啦
Stars: ✭ 93 (-44.97%)
Mutual labels:  nuxt, ssr

nuxt-env

nuxt-env inject env vars for your Nuxt app at runtime

CircleCI


🚨🛑 WARNING 🛑🚨

Runtime Config has been released in Nuxt.js and solves the problem this package was solving, so this package has been is deprecated and will not be receiving any further updates (There is some discussion in this issue in the Nuxt.js repo).


Why

Nuxt currently provides a very handy way of injecting environment variables which uses webpack substitution to inject your env vars at build time. This works most of the time, but if your build process is environment-agnostic (e.g. if you build a Docker image on CI and use the same image for staging and production), you end up with a result which has the environment baked into it (meaning that in our example, the docker image would be coupled to the environment it was built in).

This module allows you to read environment variables server side—at runtime—and inject them into your app, meaning your Nuxt bundle is decoupled from your environment variables.

⚠️ WARNING: As with the config.env option in Nuxt config, environment variables used in nuxt-env are exposed client side, so if you store secrets use the secret config option. Read more below. ⚠️

Usage

nuxt-env injects your environment variables into your Nuxt app using this.$env.

N.B. If currently use Nuxt's config.env option, fear not—nuxt-env includes those env vars in the $env object.

Get Setup

  1. Install the dependency:
yarn add nuxt-env
  1. Add to your nuxt.config.js and configure:
// nuxt.config.js

// Tell nuxt-env which env vars you want to inject
modules: [
  'other-nuxt-module',
  ['nuxt-env', {
    keys: [
      'TEST_ENV_VAR', // Basic usage—equivalent of { key: 'TEST_ENV_VAR' }
      { key: 'OTHER_ENV_VAR', default: 'defaultValue' } // Specify a default value
      { key: 'THIRD_ENV_VAR', secret: true } // Only inject the var server side
      { key: 'ANOTHER_ENV_VAR', name: 'MY_ENV_VAR' } // Rename the variable
    ]
  }]
]

Options

Env vars can be injected in a basic way, just by specifying a string in the keys option. When the provided var is an object, it can have the following attributes:

key

required

The name of the environment variable by which it can be accessed in process.env

default

A default value for the env var in case it's not present in process.env.

secret

default: false

When true, this key will only be present server side.

name

Change the name of the env var that gets injected. e.g.: { key: 'API_URL', name: 'API_ENDPOINT' } will read process.env.API_URL and add it as $env.API_ENDPOINT

Use in your application

  • Use this.$env in your components:
// any-component.vue

export default {
  computed: {
    testValue () { return this.$env.TEST_VALUE }
  }
}
  • and in your Nuxt context
// any-component.vue

export default {
  asyncData ({ app }) {
    console.log(app.$env.TEST_VALUE)
  }
}
  • and in your store:
// store/index.js

export const mutations = {
  storeEnv (commit) {
    const val = this.$env.TEST_VALUE
    commit('testValue', val)
  }
}

Develop

# First fork the repo
git clone [email protected]:your-username/nuxt-env.git
cd nuxt-env
npm i
npm run test

# To use while developing other apps:
npm link
cd ../my-other-app
npm link "nuxt-env"

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/samtgarson/nuxt-env. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

Thanks

License

The module is available as open source under the terms of the MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].