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-masked-config-plugin

v0.2.1

Published

Webpack plugin that creates a module with masked and customized configuration loaded with node-config.

Downloads

8

Readme

webpack-masked-config-plugin

npm

Synopsis

This WebPack plugin loads a configuration object from one or several config files. It optionally excludes values from the configuration according to a given mask object, and/or extends it with additional properties. The plugin then saves the resulting configuration object as a module that can be included in the asset bundles produced by WebPack.

This plugin is useful when you want to manage the front-end and back-end configuration for one or multiple apps and multiple deployment modes from a single set of configuration files.

This plugin uses node-config to load the configuration object and object-mask to mask it.

Changelog

See Changelog

Using this plugin

To use this plugin you need to add it in the plugins list in the webpack.config.js file. The following options can be specified in an object passed to the plugin constructor.

| option | type | description | |:------:|:----:|:------------| | source | string | The configuration is normally loaded from the ./config directory relative to the running process. You can optionally specify a different source directory by providing its path as the source option. This path is resolved with respect to the current working directory[^1] and assigned to the NODE_CONFIG_DIR evironment variable, which is taken into account by the config loader used in this plugin. | env | string | The config loader used in this plugin allows you to customize the default configuration depending on the value of the NODE_ENV environment. You can optionally set/override the value for this variable while loading the configuration by providing it as the env option. The original value is restored after loading the configuration. | mask | object | You can optionally mask the configuration object by specifying a masking object. This object determines which parts of the source configuration object are included in the target configuration object. All properties that are not in the mask object are excluded from the target configuration object. The masking is done by means of the nested-object-mask package. | extend | object | Optionally add values in the target configuration at build-time by extending is with the given object. The configuration is extended with the extendDeep utiliy in the the node-config package. | morph | function | Optionally transform the config object arbitrarily. The given function is called with the masked and extended config object as sole argument. It should return the target config object, which may be the given config object that was modified, or a new object. | target | string | The resulting configuration object is normally saved as a loadable module in config.js in the current working directory. You can override the location and name of this module by providing the target path as this option. | debug | boolean | When true, the steps in the transformation process are traced using the log option. | | log | Object | An object that has two methods: debug() en error(), which both take an arbitrary number of arguments and logs these appropriately. The default implementation uses console.log and console.error. |

[^1]: The value of process.cwd().

The following example instructs WebPack to:

  1. load the configuration for the production mode managed in the shared-config folder;
  2. retain only the service.host and service.port settings and remove all other sensitive server-side settings;
  3. add the value of the HOST environment variable as service.host setting;
  4. save the resulting configuration object as the index module in the build directory.
const MaskedConfig = require('./webpack-masked-config-plugin');

module.exports = {
  plugins: {
    new MaskedConfig({
      source: '../shared-config',
      env: 'production',
      mask: {
        service: {
          host: true,
          port: true
        }
      },
      extend: {
        service: {
          host: process.env.HOST
        }
      },
      target: 'build/index.js',
    }),
  },
  ...
};

Dependencies

This plugin has been tested for WebPack versions 1.0.0 till 1.12.14.

Testing

To run the tests, execute:

npm install
npm test