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-env-loader-plugin

v1.0.0

Published

A plugin for loading configuration into webpack based on environment

Downloads

44

Readme

webpack-env-loader-plugin

A plugin that extends DefinePlugin to help load configuration based on environment.

Installation

First, install with npm:

npm install webpack-env-loader-plugin --save

Add an instance of the plugin to webpack.config.js:

const EnvLoaderPlugin = require("webpack-env-loader-plugin");

module.exports = {
  ...
  plugins: [
    new EnvLoaderPlugin(options)
  ]
};

How it works

EnvLoaderPlugin will pick up configuration from files with the pattern config.{env}.json, or a custom pattern you define, in this order:

  1. First, it will look for config.default.json (or config.default.yml, if you're into that)
  2. Next, it will look for config.{env}.json, where {env} is process.env.NODE_ENV

In your javascript files processed by webpack, all configuration values are exposed under a global object (__CONFIG__ by default):

if (__CONFIG__.FOO) {
  console.log("foo");
}

If you want to trigger webpack builds with different environments, just make sure you set NODE_ENV:

NODE_ENV=production webpack

Options

env

Default: process.env.NODE_ENV

You can use this option to override process.env.NODE_ENV if you want to specify it explicitly.

reactEnv

Default: false

Add configuration that will set React to production mode if env is "production".

path

Default: process.cwd()

This is the path in which to look for config files.

filePattern

Default: config.{env}.json

Pattern to file config files. {env} is replaced by whatever env is.

namespace

Default: "CONFIG"

Object that prefixes your config variables, so they don't pollute global state. If you are using eslint, make sure you add it to globals.

loadDefault

Default: true

Load config.default.json (or whatever your filePattern is with {env} set to default) before loading other configuration files.

loadLocalOverride

Default: null

If you specify a path in this option, the plugin will load the file and override all other configuration EXCEPT process.env;

loadFromProcessEnv (TODO, not yet implemented)

Default: true

Override configuration with values from process.env if they are found.

log

Default: true

Log progress to console.