@esmap/config
v0.1.0
Published
Configuration schema, loading, and validation for esmap framework
Downloads
18
Readme
@esmap/config
Configuration schema, loading, and validation for the esmap framework.
Installation
pnpm add @esmap/configConfig File
Create one of the following in your project root (searched in this order):
esmap.config.tsesmap.config.jsesmap.config.mjsesmap.config.json
defineConfig
Type-safe configuration definition:
// esmap.config.ts
import { defineConfig } from '@esmap/config';
export default defineConfig({
apps: {
'@myorg/checkout': {
path: '/checkout',
},
'@myorg/cart': {
path: '/cart',
},
},
shared: {
react: 'https://cdn.example.com/react.js',
'react-dom': 'https://cdn.example.com/react-dom.js',
},
server: {
port: 3000,
storage: 'filesystem', // 'filesystem' | 's3' | 'redis'
},
});Loading
import { loadConfig, loadConfigFile } from '@esmap/config';
// Auto-discover (searches cwd for config files)
const config = await loadConfig();
// Load a specific path
const config = await loadConfigFile('/path/to/esmap.config.ts');Supported formats: .ts, .js, .mjs (dynamic import), .json (parsed).
Validation
import { validateConfig, assertValidConfig } from '@esmap/config';
import type { ConfigFieldError } from '@esmap/config';
// Returns error list
const errors: readonly ConfigFieldError[] = validateConfig(unknownData);
// Returns type-safe config if valid, throws otherwise
const config = assertValidConfig(unknownData);resolveConfig
Fills in defaults for optional fields:
import { resolveConfig } from '@esmap/config';
import type { ResolvedConfig } from '@esmap/config';
const resolved: ResolvedConfig = resolveConfig(config);