Skip to content

Instantly share code, notes, and snippets.

@nothingismagick
Last active September 20, 2018 13:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nothingismagick/b8c64591ac8ec9bc59310670058272b8 to your computer and use it in GitHub Desktop.
Save nothingismagick/b8c64591ac8ec9bc59310670058272b8 to your computer and use it in GitHub Desktop.
Quasar ENV

So you want to use ENV vars. Good on you. Here is a quick snippet to help you manage that.

/config/index.js

module.exports = {
  NODE_ENV: 'development',
  FOO: 'bar'
}

/src/pages/Index.vue

<template>
  <q-page class="flex flex-center">
    <div class="layout-view">
      API: {{ api }}
      <br>
      FOO: {{ bar }}
    </div>
  </q-page>
</template>

<style>
</style>

<script>
export default {
  name: 'PageIndex',
  data () {
    return {
      api: process.env.API,
      bar: process.env.FOO
    }
  }
}
</script>

/quasar.conf.js

const config = require('./config/index.js')
...
module.exports = function (ctx) {
  return {
    ...
    build: {
      env: ctx.dev
        ? { // so on dev we'll have
          API: JSON.stringify('https://dev.api.com'),
          FOO: JSON.stringify(config.FOO)
        }
        : { // and on build (production):
          API: JSON.stringify('https://prod.api.com')
        },
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment