Skip to content
Load targeted variables into your quasar project
JavaScript
Branch: dev
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
demo chore(docs): update demo Jul 14, 2019
docs chore(docs): update demo Jul 14, 2019
src
.editorconfig Initial code Mar 26, 2019
.eslintrc.js Initial code Mar 26, 2019
.gitignore Initial code Mar 26, 2019
.npmignore chore: ignore .git folder in npm package May 3, 2019
LICENSE Initial commit Mar 26, 2019
README.md fix: link to demo doesn't work in readme #5 Jul 21, 2019
_redirects chore: github hostory mode Jun 6, 2019
package.json chore: update dependencies Jul 14, 2019
yarn.lock chore(deps-dev): bump eslint from 6.0.1 to 6.1.0 Jul 22, 2019

README.md

QEnv (@quasar/qenv)

official icon npm (scoped)

GitHub code size in bytes GitHub repo size in bytes npm

This project is an official Quasar v1 CLI App Extension.

@quasar/qenv is a CLI App Extension for Quasar Framework v1. It will not work with legacy versions of Quasar Framework.

This work is currently in beta and there are expected changes while things get worked out. Your help with testing is greatly appreciated.

Test Project

In demo folder of app-extension-qenv.

Demo

Can be found here.

Install

To add this App Extension to your Quasar application, run the following (in your Quasar app folder):

quasar ext add @quasar/qenv

Quasar CLI will retrieve it from NPM and install the extension.

You will be asked a couple of questions. Type in your answers:

? What name would you like to use for your Common Root Object ('none' means to not
 use one)? none
? For security, would you like your .quasar.env.json file automatically added to .
gitignore? Yes

Selecting [enter] on your keyboard will give you the defaults. There will be no common root object and the .quasar.env.json will be added to your .gitignore.

Also, it is highly recommended to add your .quasar.env.json file to your .gitignore. It really does not belong in your repository as it may contain sensitive data.

Accessing the data

Any specified data in .quasar.env.json will be placed in process.env at the browser level.

If you specified a common root object, say MyData, then the data will be placed at process.env.MyData.

Tips

Be aware, if you have something like this in your .quasar.env.json:

"APP_PORT": "4000"

Then you will need to use the parseInt() function as it will be propogated to the browser code as a string. You should really do it this way:

"APP_PORT": 4000

Now, the variable will be accessible in the browser as a number.

Format

The format of the .quasar.env.json is as follows:

{
  "development": {
    "ENV_TYPE": "Running Development",
    "ENV_DEV": "Development"
  },
  "production": {
    "ENV_TYPE": "Running Production",
    "ENV_PROD": "Production"
  },
  "test": {
    "ENV_TYPE": "Running Test",
    "ENV_Test": "Test"
  }
}

This is the default that is installed and you will need to modify it to fit your needs.

You can add as many environments as needed (top-level keys). You are not restricted to the development, production and test that come by default. And, you can add as many variables under those environment types as you like.

Specifying environment

So, how is this accessed?

You will need to modify your package.json in the scripts area. Let's take a look at an example:

  "scripts": {
    "dev": "QENV=development quasar dev",
    "test-dev": "QENV=test quasar dev",
    "combined": "QENV=development+test quasar dev",
    "build": "QENV=production quasar build"
  },

Basically, you need to set the QENV environment variable for Node. You specifiy the key that you want for the propgated data.

QEnv with Windows

Many thanks to NicksonYap for the following information:

QEnv will work on Windows by additionally installing cross-env.

npm install --save-dev cross-env

or

yarn --dev cross-env

Then, in package.json:

"dev": "cross-env QENV=development quasar dev"

Qenv with Docker

QEnv will work with Docker by using the following syntax to inject your QENV variable into Node:

$ sudo docker run [...] -e QENV="development"

Chaining environments

Look at the combined script. Absolutely, you can chain two or more together. When doing this, if there is any conflicting variables, the last one in wins.

In other words:

"combined": "QENV=development+test quasar dev",

will give different results than:

"combined": "QENV=test+development quasar dev",

And to be clear, you would do the following to run it:

# npm
npm run combined

# or

# yarn
yarn combined

Uninstall

To uninstall:

quasar ext remove @quasar/qenv

Donate

If you appreciate the work that went into this App Extension, please consider donating to Quasar.

You can’t perform that action at this time.