Git Product home page Git Product logo

inject-env-browser-run's Introduction

inject-env-browser-run

It injects environment variables into your browser index.html

Why?

Browser doesn't have runtime access to the environment variables. So when we try to dockerize Frontend projects we intend to use --build-args to pass the variables to the image in build-stage. But this couples our images with environment it was built for.

For example: A project that requires an API_URL and will be deployed to dev, staging, qa and production environments will have to be built 4 times for every environment. Every time you release a new version of your application you will have to provide 4 different images.

More explantion:

Solution:

define your required variables. and inject this cli in your CMD and it will generate a file called env-config.js you could load into your html files and it will add an object called _env_ to your window object.

Install

$ npm install inject-env-browser-run

Demo

Check the demo/ folder for more guidance.

Config

You have to define a list of the required variables.

In package.json

"inject-env-browser-run": {
  "required": [
    "HOST",
    "BLOG_HOST",
    "DEBUG_LEVEL",
    "APP_TITLE"
  ]
}

Usage

const injectEnvBrowserRun = require('inject-env-browser-run');

injectEnvBrowserRun('src/foo/bar');
//=> 'creates an `env-config.js` file in the path src/foo/bar'

Then load env-config.js in your html file.

Note: don't bundle it in your JS bundle

API

injectEnvBrowserRun(dest)

dest

Type: string

the destination where the env-config file will be created

CLI

$ npm install --g inject-env-browser-run
$ inject-env-browser-run --help

	Usage
		$ inject-env-browser-run

	Options
		--dest  the destination where the env-config file will be created [Required]

	Examples
		$ inject-env-browser-run --dest src/foo/bar
    creates an `env-config.js` file in the path src/foo/bar

inject-env-browser-run's People

Contributors

saadshahd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

chilldev

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.