This package can be utilised to extract specific environment variables at runtime.
Another option for this package is to pull the version from your package.json which is useful for versioning your service worker.
Using yarn:
$ yarn add vue-enverywhere
In VueJs:
Import the package
//in vue.confg.js
const vueEnverywere = require('vue-enverywhere');
module.exports = {
configureWebpack: {
...
plugins: [
new vueEnverywere({ filename: 'env-vars.js' })
],
},
}
This snippet is from service worker but this file can be imported anywhere in your app
importScripts('./env-vars.js')
const inDevelopment = ENVERYWHERE_DEVELOPMENT
VUE_APP_API_URL="http://localhost:8080"
VUE_APP_BASE_URL="******"
VUE_APP_ROUTER_MODE="hash"
ENVERYWHERE_DEVELOPMENT="false"
ENVERYWHERE_BASE_PREFIX="/example.api."
const ENVERYWHERE_DEVELOPMENT = 'false'
const ENVERYWHERE_BASE_PREFIX = '/example.api.'
const VERSION = '1.0.1'
Only env variables prefixed with ENVERYWHERE_
will be exported.
Version is imported from the package.json version number, if you have no version in your package.json it wont import. I can alter the package to have this as an option in the future.
$ yarn build
Please post a bug report or issue on GitHub.