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

bundle-config

v1.1.11

Published

Configuration management for bundlers

Downloads

22

Readme

npm Gitpod ready-to-code

Bundle config

Intended to be used by bundlers to bundle a configuration object built upon many selected files - easing developing, testing, etc.

Config gathering

The gathering will create one configuration object from the files of a folder and the configuration given as parameter.

The configuration engine will look for many files each overwriting the previous one. Each file will be searched with extension .aml, .yaml, .yml, .json and .js. Note that .json will read hjson that is basically a more forgiving json.

Bundler-oriented configuration

This library is made so that a configuration is read in order to be available to bundle or be used by the running program.

Files list

The file names that will be checked will be composed of two parts. File names are composed of parts separated with dots.

[machine].[build].[ext]

Extensions yaml, yml then json will be tried in the first pass. All will be taken if given.

1. Machine-dependant

The first file-name part will be default, [hostname] or local. The hostname of a machine can be queried to have a config file that applies to one machine. The local files are meant to not be tracked by your version control system.

[.gitignore]
config/local.*

2. Build-dependant

When gathering the configuration, you give the build specifications - an array of string. This let you specify the instance, production state, and whatever agnostically. For a client/server application, you could have the possible specs ['client', 'dev'], ['server', 'prod'] or combinations.

The specification ['A', 'B', 'C'] will give these build names: ['', 'A', 'B', 'C', 'A.B', 'A.C', 'B.C', 'A.B.C']

Therefore, if your config folder contains a file local.server.dev.json, this file will be used only in case of server-dev build to override a default.yaml config.

Programatic configurations

The first pass will read all the static configurations (aml, yaml and json) then a second pass will read all the js files the same way and execute them with one global argument : config, that is the config object as described here.

Exemple of programatic configuration :

config.set('db:url', 'mongodb://'+config.get('db:server')+':'+config.get('db:port'));

Installation and usage

npm install bundle-config

Manually

const extract = require('bundle-config');
function extract(path: string = 'config', specs: string[] = [], env: string[] = null, argv: string[] = null)

This function returns the configuration object extracted from a folder and the environment.

  • path is the path of the folder containing the config files
  • specs is the build-specification
  • env is the list of environment variables name to include in the configuration
  • argv is the list of command-line parameter names to include in the configuration

For env and argv, please refer to merge-config on which this library is built

While bundling

When bundling, the variable has to be declared if using typescript:

declare var config: any;

After, the value is defined like globally. Take care that the value is NOT defined but replaced; If the value is used several times, it is better to begin with a local affectation then use the variable.

const serverConfig = config;
...
app.listen(serverConfig.http.port);

Plugin options

  • name?: string The variable in which the configuration is stored. Defaults to config

The next ones are given to the extractor (all as-is except for specs that has the bundle name added)

  • path: string The path where all the config files are stored. Defaults to config. If relative, it is given from the execution directory.
  • specs?: string[] The specifications to find the config files (server/client, dev/prod, ...)
  • env?: string[]
  • argv?: string[]

Webpack

...
var {webpack: ConfigPlugin} = require('bundle-config');
...
module.exports = {
	...
	plugins: [
		...
		new ConfigPlugin({ ... })
	],
	...
};

Rollup

...
const {rollup: ConfigPlugin} = require('bundle-config');
...
export default {
	...
	plugins: [
		...
		new ConfigPlugin({ ... })
	],
	...
};

Host-name

To find out the exact host-name used for a machine, install the package and in the dist folder is a stand-alone query-hostname.js script that can be directly executed by node to display the current machine host-name.