npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

jvjr-docker-env

v1.1.1

Published

Environment variables on docker with Vue and React

Downloads

222

Readme

jvjr-docker-env

Change env variables when run your docker image of your Vue/React app

Node >= 10

Installing

npm install jvjr-docker-env

This will install jvjr-docker-env as dependency, and will add a Dockerfile-jvjr functional example, a script jvjr-entrypoint.sh and jvjr-env.json file with env variables from .env file into the base directory of your project.

  • Dockerfile-jvjr is a functional Dockerfile example to a basic Vue project, you can use it as it is.
  • The script jvjr-entrypont.sh (as you can see into Dockerfile-jvjr) will be the entrypoint.
  • The jvjr-env.json file with env variables will be used by jvjr-docker-env library.

If you change the env file and need to regenerate jvjr-env.json:

npm run jvjr-build

This action will be added to build script on your package.json.

Usage

If we have this .env file:

VUE_APP_WEB_SERVICE=http://192.168.12.28
VUE_APP_OTHER=http://localhost

jvjr-docker-env will generate a jvjr-env.json file like this:

{
    "WEB_SERVICE"="$VUE_APP_WEB_SERVICE",
    "OTHER"="$OTHER"
}

So you can use it on your code:

import EnvProvider from 'jvjr-docker-env';

export default class MyClass {
    private webService: any;
    constructor() {
        this.webService = EnvProvider.value('WEB_SERVICE');
    }
} 

Before you build your docker image, you will probably need to modify Dockerfile-jvjr file. You need to tell jvjr-entrypoint.sh where the dist directory is and the prefix of *js files.

For example:

COPY --from=build-stage /app/<my dist dir> /usr/share/nginx/html

COPY --from=build-stage /app/jvjr-entrypoint.sh /
COPY --from=build-stage /app/jvjr-env.json /
RUN chmod +x /jvjr-entrypoint.sh

EXPOSE 80

ENTRYPOINT [ "/jvjr-entrypoint.sh", "/usr/share/nginx/html/<path to js files>", "<prefix of your js files>" ]
  • <my dist dir>, usually 'dist' or 'build'
  • <path to js files>, usually 'js' or 'static/js'
  • <prefix of your js files>, usually 'app' or 'main'

After you build your docker image, if you set env var for example in your docker run command line

docker run -d --name example -e VUE_APP_WEB_SERVICE=locahost example:latest

then webService value will be localhost.

But if you din't set VUE_APP_WEB_SERVICE, wevService value will be http://192.168.12.28, which is the one we have into .env file.

See https://github.com/juanise/jvjr-docker-env-example for a React example.