Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@pascholda1/vue-runtime-config-plugin

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pascholda1/vue-runtime-config-plugin

A VueJS plugin to read JSON config files per environment at runtime.

  • 3.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

@pascholda1/vue-runtime-config-plugin

A VueJS plugin to read JSON config files per environment at runtime.

Works with Vue2. Vue3 support coming soon.

Installation

npm i @pascholda1/vue-runtime-config-plugin

Usage

Basic Usage


import Vue from 'vue';

import vueRuntimeConfigPlugin from '@pascholda1/vue-runtime-config-plugin';

Vue.use(vueRuntimeConfigPlugin)

(async () => {

  // fetch the config files from /config
  const config = await vueRuntimeConfigPlugin.loadEnvironment({
    environment: process.env.NODE_ENV
  });

  console.log(config)

  // init App
  new Vue({
    render: h => h(App),
  }).$mount('#app');
})


Advanced Usage


import Vue from 'vue';

import {VueRuntimeConfigPlugin} from '@pascholda1/vue-runtime-config-plugin';

const vueRuntimeConfigPlugin = new VueRuntimeConfigPlugin({
  configPath: "/my/config/path",
  staticConfig: process.env
})

Vue.use(vueRuntimeConfigPlugin)

(async () => {

  // fetch the config files from /my/config/path
  const config = await vueRuntimeConfigPlugin.loadEnvironment({
    environment: process.env.NODE_ENV,
    forceFetch: true
  });

  console.log(config)

  // init App
  new Vue({
    render: h => h(App),
  }).$mount('#app');
})


Access the configuration Object / Switch environment at runtime


<template>
  <div id="app">
    <pre>{{ $config }}</pre>
  </div>
</template>

<script>

export default {
  name: 'App',
  created() {
    console.log(this.$config)
  },
  methods: {
    async switchConfigEnvironment(environment) {
      await this.$vueRuntimeConfigPlugin.loadEnvironment({
        environment
      });

      // Note that the $config object is NOT reactive
      await this.$forceUpdate()
    }
  }
};
</script>


Config Files and Config merging

Your config directory should contain min. two Files. The default.config.json and the one for each environment eg. development.config.json

the environment config will be merged into the default config which will be merged into the static config which was passed to the constructor.

If you use nested configurations in your file the plugin will overwrite the whole first level Object.

Keywords

FAQs

Package last updated on 16 Aug 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc