config.xbuild.ts
config.xbuild.ts is the main xBuild configuration file.
Basic Structure
ts
import type { xBuildConfig } from '@remotex-labs/xbuild';
export const config: xBuildConfig = {
common: {
types: true,
declaration: true,
esbuild: {
sourcemap: true,
platform: 'node'
}
},
variants: {
main: {
define: {
DEBUG: true
},
esbuild: {
entryPoints: ['src/index.ts'],
outdir: 'dist',
bundle: true,
format: 'esm'
}
}
},
serve: {
dir: 'dist',
start: true
}
};
// also supported:
// export default config;Top-Level Fields
variants(required): named build variants.common(optional): shared config merged into all variants.verbose(optional): enable detailed logs.userArgv(optional): custom CLI options using yargsOptions.serve(optional): development server config.
serve
For full serve options and examples, see:
variants
Each variant requires esbuild.entryPoints and can override anything from common.
ts
variants: {
dev: {
esbuild: {
entryPoints: ['src/index.ts'],
outdir: 'dist/dev',
sourcemap: true,
minify: false
}
},
prod: {
define: { DEBUG: false },
esbuild: {
entryPoints: ['src/index.ts'],
outdir: 'dist/prod',
minify: true,
bundle: true
}
}
}common
Shared defaults for all variants:
ts
common: {
types: { failOnError: true },
declaration: { bundle: true, outDir: 'dist/types' },
esbuild: {
platform: 'node',
target: ['node20']
}
}types and declaration
xBuild handles TypeScript checks and declaration generation in lifecycle hooks:
typesis handled in the buildstartphase.declarationis handled in the buildendphase (only when build has no errors).
types
Supported forms:
ts
types: true
// or
types: {
failOnError: true
}Behavior:
types: trueenables TS diagnostics.- If
failOnErrorisfalse, diagnostics are reported as warnings and build can continue. - If
failOnErroristrue(or not set), TS errors fail the build.
declaration
Supported forms:
ts
declaration: true
// or
declaration: {
outDir: 'dist/types',
bundle: true
}Behavior:
- Declaration generation runs only after a successful build.
outDiroverrides declaration output directory.
Bundle behavior:
bundledefault istrue.- When
bundle: true, xBuild uses declaration bundling (emitBundle) and creates bundled.d.tsoutputs from entry points. - When
bundle: false, xBuild emits per-file declarations (emit).
Example:
ts
common: {
types: { failOnError: true },
declaration: {
bundle: true,
outDir: 'dist/types'
}
}define + Macros
define values are used by macros like $$ifdef, $$ifndef, and $$inline.
ts
define: {
DEBUG: true,
PRODUCTION: false
}Lifecycle Hooks
For complete lifecycle hook docs and context details, see:
Export Style
configFileProvider supports both:
export const config = { ... }export default { ... }
TypeScript Autocomplete
To get macro and config typings in TS projects:
json
{
"compilerOptions": {
"types": [
"node",
"@remotex-labs/xBuild"
]
}
}