consul-env-webpack-plugin

1.0.2 • Public • Published

A webpack plugin that convert the KV Store Endpoints in environment variables.

The KV Store Endpoints is a feature of consul.io.

dotenv webpack consul-env-webpack-plugin

Installation

Include the package locally in your repository.

npm install consul-env-webpack-plugin -D

yarn add consul-env-webpack-plugin -D

Description

consul-env-webpack-plugin wraps node-consul and Webpack.DefinePlugin. As such, it takes the JSON from the consul server and parse the keys to process.env with Webpack.DefinePlugin.

Usage

The plugin can be installed with little configuration needed. Once installed, you can access the variables within your code using process.env.

The example bellow shows a standard use-case

Configure the JSON in your consul server
{
  "MY_API": "https://10.5.1.1"
}
Add it to your Webpack config file
// webpack.config.js
const ConsulPlugin = require('consul-env-webpack-plugin')
 
module.exports = {
  ...
  plugins: [
    new ConsulPlugin({
      path: 'config/front/data', //path to keys
      consul: {
        ... //node-consul options - see https://github.com/silas/node-consul
      }
    })
  ]
  ...
};
Use in your code
// provider.js
console.log(process.env.MY_API);
// 'https://10.5.1.1'

Properties

Use the following properties to configure your instance.

  • path ('config/front/data') - The path API to your data endpoints.
  • consul (options) - This options are necessary to config your consul, see default options in node-consul.

The following example shows how to set any/all arguments.

module.exports = {
  ...
  plugins: [
    new ConsulPlugin({
      path: 'config/front/data',
      consul: null //load the default options of node-consul
    })
  ]
  ...
};

Package Sidebar

Install

npm i consul-env-webpack-plugin

Weekly Downloads

1

Version

1.0.2

License

MIT

Unpacked Size

8.12 kB

Total Files

5

Last publish

Collaborators

  • marlonmleite