environment-variables-webpack-plugin

Webpack plugin to replace in your code environment variables defined as %%var%% from a json file


Keywords
webpack, plugin, environment, variables
License
ISC
Install
npm install environment-variables-webpack-plugin@1.0.3

Documentation

Environment variable replacing plugin for WebPack

How to use

  1. Add some variable in your code following pattern %%var%%
    new AuthConfiguration({endpoint: "%%my.var%%"})
  1. Create an environment variable set JSON file
// config/dev.json
    {
        "my": {"var": "Hello!"}
    }
  1. Add reference to the plugin from your webpack configuration
    //config/webpack.dev.js

    var webpackMerge = require('webpack-merge');
    var EnvironmentVariablesPlugin = require('environment-variables-webpack-plugin');
    var commonConfig = require('./webpack.common.js');

    module.exports = webpackMerge(commonConfig, {


        plugins: [
            new EnvironmentVariablesPlugin({
                optionsFile: 'config/dev.json',
                chunks: ['angularApp'],
                skipUndefinedVars: true // default false
            })
        ],

    });