{"id":19408,"library":"cname-webpack-plugin","title":"CnameWebpackPlugin","description":"Webpack plugin to generate a CNAME file (used by GitHub Pages, Netlify, etc.) for custom domains during build. v3.0.0 is stable, low maintenance cadence. Key differentiator: minimal, zero-config approach for adding a CNAME file to webpack output. Supports webpack 4 and 5. No dependencies beyond webpack peer.","status":"active","version":"3.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/lozinsky/cname-webpack-plugin","tags":["javascript","webpack","cname","production"],"install":[{"cmd":"npm install cname-webpack-plugin","lang":"bash","label":"npm"},{"cmd":"yarn add cname-webpack-plugin","lang":"bash","label":"yarn"},{"cmd":"pnpm add cname-webpack-plugin","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency required for plugin to work","package":"webpack","optional":false}],"imports":[{"note":"ESM import available in v3+? Actually this package is CJS-only, do not default import.","wrong":"import CnameWebpackPlugin from 'cname-webpack-plugin';","symbol":"CnameWebpackPlugin","correct":"const CnameWebpackPlugin = require('cname-webpack-plugin');"},{"note":"For ESM projects, use default import. Common mistake is destructuring require.","wrong":"const { CnameWebpackPlugin } = require('cname-webpack-plugin');","symbol":"CnameWebpackPlugin","correct":"import CnameWebpackPlugin from 'cname-webpack-plugin';"},{"note":"TypeScript users: type import only exists if types are provided. Package does not ship types; use @types/cname-webpack-plugin.","wrong":"","symbol":"CnameWebpackPlugin (type)","correct":"import type { CnameWebpackPlugin } from 'cname-webpack-plugin';"}],"quickstart":{"code":"// webpack.config.js\nconst CnameWebpackPlugin = require('cname-webpack-plugin');\n\nmodule.exports = {\n  entry: './src/index.js',\n  output: {\n    filename: 'bundle.js',\n    path: __dirname + '/dist',\n  },\n  plugins: [\n    new CnameWebpackPlugin({\n      domain: 'example.com',\n    }),\n  ],\n};","lang":"javascript","description":"Shows basic usage: import plugin, add to webpack plugins array with domain option."},"warnings":[{"fix":"Rename import/require to CnameWebpackPlugin and update constructor call.","message":"Version 1.x used a different API: new CnamePlugin(); v2+ renamed to CnameWebpackPlugin.","severity":"breaking","affected_versions":"<=1.0.0"},{"fix":"Ensure domain is a valid hostname (e.g., 'example.com' without protocol or trailing slash).","message":"Plugin does not validate domain format; invalid domain will produce a malformed CNAME file.","severity":"gotcha","affected_versions":">=2.0.0"},{"fix":"Use one plugin instance per compiler or manually handle with multiple compilations.","message":"Plugin writes only to the main output path; does not work with multi-compiler or multi-output configs.","severity":"gotcha","affected_versions":">=2.0.0"},{"fix":"If using webpack 4, pin to version 2.x. Otherwise upgrade to webpack 5.","message":"Webpack 4 support will be removed in future major version; upgrade to webpack 5.","severity":"deprecated","affected_versions":">=3.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Use require('cname-webpack-plugin') instead of import.","cause":"Using ES6 import incorrectly on a CJS module.","error":"TypeError: CnameWebpackPlugin is not a constructor"},{"fix":"Run 'npm install cname-webpack-plugin --save-dev' and ensure node_modules exists.","cause":"Missing package installation or incorrect path.","error":"Error: Cannot find module 'cname-webpack-plugin'"},{"fix":"Pass an object with a 'domain' key: new CnameWebpackPlugin({ domain: 'example.com' });","cause":"Options object missing required 'domain' property.","error":"ValidationError: Invalid options object. Cname Webpack Plugin has been initialized using an options object that does not match the API schema."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}