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

webpack-inject-environment-variables

v1.0.0

Published

A webpack plugin extracted from Facebook create-react-app that allows you to inject environment variables to a javascript client during CI

Downloads

3

Readme

Webpack Inject Environment Plugin

A webpack plugin extracted from Facebook create-react-app that allows you to inject environment variables to a javascript client during continuous integration. This plugin can be used in any context, for a shared javascript library or React application or Vue application.

Installation

npm install --save-dev webpack-inject-environment-variables

Usage

Require the plugin with your Webpack configuration (or applicable extensions if you're using a framework) and then add a new InjectEnvironmentPlugin to the plugins.

const InjectEnvironmentPlugin = require('webpack-inject-environment-variables');

module.exports = {
    plugins: [
        new InjectEnvironmentPlugin({regex: /^MY_NAMESPACE/i}),
    ]
}

The InjectEnvironmentPlugin class takes a configuration object with two arguments:

| Argument | Type | Default | Purpose | | --- | --- | --- | --- | | regex | Regex | | All environment variables on the system that are read by the plugin will be filtered by their keys against the regex pattern you provide. Only environment variables starting with MY_NAMESPACE in the above example will be considered with that regex. MY_NAMESPACE_ID, MY_NAMESPACE_NAME will be, MY_ID will not. You can change this regex to be whatever you want. | | environment | string | production | Specify the default environment for the script to run in. |

Purpose

This plugin allows you to store environment-specific or sensitive data in a .env file or within the build environments themselves and let the application access their values even though it is being run in the browser. The alternative to using environment variables for this use case is to have multiple hard-coded configurations with some environment detection logic - which can become messy. With this solution you inject the values that change per project and the application can become agnostic of its environment.

This plugin works best if you create a simple Docker environment that uses your .env file. The environment variables don't need to be available on any production server, only on the CI build server or when you build a distributable package for your project with Webpack.

Origin

Most of this code was taken from the Facebook create-react-app build scripts and refactored to be decoupled from React logic and other plugins they use in their scafolding tool. In addition, the new ES6 syntax makes the code more modular for future modifications should they be necessary.

Contributing and Distribution

This plugin is licensed as MIT, all contributions are welcome for any edge cases this plugin might not cover.

A distributable can be created by running npm run build in a Node environment with version 12. Use npm pack and install the resulting tgz file in your project to test your modifications.