@zokugun/configdotts-merge
v0.5.0
Published
Merge config.ts files while preserving comments
Readme
@zokugun/configdotts-merge
@zokugun/configdotts-merge is a TypeScript library for merging multiple configuration files (such as Vite, ESLint, Prettier, etc.) written in .ts, while preserving comments.
- Supports
export default {...},export default anyFunction({...}),export default variable, and function/arrow-based configs. - Preserves comments.
- Uses TypeScript’s AST for safe, reliable merging.
Features
- Comment Preservation: No more lost documentation in your config files!
- Smart Merging: Last value wins for conflicts; merges arrays and objects intelligently.
- Grouped Merging: Organize array elements and object properties with
// configdotts/<group>sections. - TypeScript Native: Built on TypeScript’s AST for perfect
.tscompatibility. - Supports Major Tools: Vite, ESLint, Prettier, Tailwind, and more.
Getting Started
With node previously installed:
npm install @zokugun/configdotts-mergeimport { readFileSync } from 'fs';
import { merge } from '@zokugun/configdotts-merge';
const baseConfig = readFileSync('vite.base.config.ts', 'utf-8');
const siteConfig = readFileSync('vite.site.config.ts', 'utf-8');
const mergedConfig = merge(baseConfig, siteConfig);
console.log(mergedConfig); // Merged config, comments intact!Grouped Sections
Use // configdotts/<group> comments to divide an array or object into named sections:
export default defineConfig({
// configdotts/Build options
build: {
sourcemap: true,
},
// configdotts/Server options
server: {
port: 3000,
},
});When two configs contain groups, matching groups are merged together and new groups are appended in their source order.
The same behavior applies to array elements:
export default configure([
// configdotts/Language rules
javascript(),
typescript(),
]);Empty groups are retained, comments remain attached to their sections, and trailing commas are preserved when both inputs use them.
Donations
Support this project by becoming a financial contributor.
License
Copyright © 2025-present Baptiste Augrain
Licensed under the MIT license.
