Webpack Plugin for Node-Config

1.0.10 · maintenance · verified Tue Apr 21

node-config-webpack is a Webpack plugin designed to integrate the `config` module's functionality directly into Webpack builds. It replaces the dynamic runtime loading of configuration, characteristic of `node-config`, with a compile-time mechanism. This approach ensures that environment-specific configuration values are embedded directly into the bundled output, eliminating the need to include the `config` module as a runtime dependency for applications where configuration is static at build time. The plugin supports injecting configuration either into `process.env` (with options for key coercion to uppercase or direct object assignment) or as a global constant within the bundle. The current stable version is 1.0.10. While not under rapid development, it provides a stable solution for environments that leverage `node-config` and require optimized, compile-time configuration embedding, offering a direct integration path not typically found in generic Webpack `DefinePlugin` setups.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates basic setup of `node-config-webpack` in `webpack.config.js` to inject configuration into `process.env` at compile time.

const NodeConfigWebpack = require('node-config-webpack');
const path = require('path');

module.exports = {
  mode: 'development',
  entry: './src/index.js',
  output: {
    filename: 'bundle.js',
    path: path.resolve(__dirname, 'dist'),
  },
  plugins: [
    new NodeConfigWebpack({
      // Example: Inject config into process.env, coercing keys to uppercase
      env: true
    })
  ],
  // Ensure 'config' module is not externalized if using node-externals
  externals: [
    // In a server-side webpack config, if using webpack-node-externals,
    // you MUST allowlist 'config' for this plugin to work.
    // e.g., nodeExternals({ allowlist: ['config'] })
  ]
};

// src/index.js example (assuming you have a 'config' package and a 'config/default.json' with { "version": "1.0.0" })
// console.log('Configuration version is', process.env.VERSION); // Output: Configuration version is 1.0.0

view raw JSON →