{"id":19412,"library":"config-webpack","title":"config-webpack","description":"config-webpack (v1.0.5) is a Webpack plugin that bridges node-config into client-side bundles. It replaces global references (default `CONFIG`) with resolved config values via Webpack's DefinePlugin, supporting deployment-, instance-, local files, and environment variables. Compatible with Webpack 1–4 and node-config 1–3. Unlike runtime config solutions, it bakes config at build time, making it immutable and suitable for single-page apps. The plugin only injects referenced keys, but beware that top-level objects like `CONFIG` can leak the entire config even if gated behind a condition.","status":"maintenance","version":"1.0.5","language":"javascript","source_language":"en","source_url":"https://github.com/arthanzel/node-config-webpack","tags":["javascript","config","node-config","webpack","plugin"],"install":[{"cmd":"npm install config-webpack","lang":"bash","label":"npm"},{"cmd":"yarn add config-webpack","lang":"bash","label":"yarn"},{"cmd":"pnpm add config-webpack","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency: node-config reads config files provided by this package","package":"config","optional":false},{"reason":"peer dependency: provides the plugin API","package":"webpack","optional":false}],"imports":[{"note":"Package is CommonJS-only; neither ESM nor named export is supported.","wrong":"import ConfigWebpackPlugin from 'config-webpack';","symbol":"ConfigWebpackPlugin","correct":"const ConfigWebpackPlugin = require('config-webpack');"},{"note":"CONFIG is a global injected at build time, not an importable symbol.","wrong":"import { CONFIG } from 'config-webpack';","symbol":"CONFIG","correct":"if (CONFIG.myKey) { … }"},{"note":"Must be instantiated with `new` when adding to webpack plugins array.","wrong":"plugins: [ConfigWebpackPlugin()]","symbol":"new ConfigWebpackPlugin()","correct":"plugins: [new ConfigWebpackPlugin()]"}],"quickstart":{"code":"// webpack.config.js\nconst ConfigWebpackPlugin = require('config-webpack');\nconst path = require('path');\n\n// Ensure config files exist\n// config/default.json: { \"apiUrl\": \"http://localhost:3000\" }\n// config/production.json: { \"apiUrl\": \"https://api.example.com\" }\n\nmodule.exports = {\n  entry: './src/index.js',\n  output: {\n    path: path.resolve(__dirname, 'dist'),\n    filename: 'bundle.js',\n  },\n  plugins: [\n    new ConfigWebpackPlugin(),\n  ],\n};\n\n// src/index.js\nconsole.log('API URL:', CONFIG.apiUrl);\n// In dev: 'http://localhost:3000'\n// In production build: 'https://api.example.com'","lang":"javascript","description":"Basic setup: install, configure webpack plugin, use CONFIG global in source."},"warnings":[{"fix":"Only reference specific keys like CONFIG.myKey; avoid logging or spreading the CONFIG object.","message":"Using CONFIG directly (e.g. console.log(CONFIG)) leaks the entire config object even if inside a false conditional, because Webpack replaces CONFIG before tree-shaking.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Treat CONFIG as readonly; do not reassign properties.","message":"Config is immutable after replacement. Attempting to assign like CONFIG.key = value throws an error.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Stick to webpack 4 or consider alternatives like @mhassan1/webpack-node-config.","message":"Webpack 5 is not supported. The peer dependency only allows webpack 1–4.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Evaluate maintenance status; consider switching to a modern alternative.","message":"Package is effectively unmaintained: last release 2019, no updates for webpack 5 or ESM.","severity":"deprecated","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Run npm install config-webpack in your project root.","cause":"config-webpack is not installed or not in node_modules.","error":"Error: Cannot find module 'config-webpack'"},{"fix":"Use const ConfigWebpackPlugin = require('config-webpack');","cause":"Importing as default import in ESM context, but package is CommonJS.","error":"TypeError: ConfigWebpackPlugin is not a constructor"},{"fix":"Ensure new ConfigWebpackPlugin() is in your plugins array and the config is used by webpack.","cause":"ConfigWebpackPlugin not added to webpack plugins array, or webpack config not processed.","error":"ReferenceError: CONFIG is not defined"},{"fix":"Run npm install config.","cause":"Missing peer dependency config.","error":"Module build failed: Error: Cannot find module 'config'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}