Skip to content

xbuild.config.ts ​

All build settings live in xbuild.config.ts (or .js). xBuild loads it from the working directory by default; change the path with --config.

Basic Structure ​

ts
import type { xBuildConfig } from '@remotex-labs/xbuild';

const config: xBuildConfig = {
    declaration: true,
    buildOnError: false,
    noTypeChecker: false,
    esbuild: {
        entryPoints: [ './src/index.ts' ],
        bundle: true,
        minify: true,
        format: 'esm'
    },
    serve: {
        active: true,
        port: 8080,
        host: 'localhost'
    }
};

export default config;

Multiple Configurations ​

Export an array to produce several outputs in one run. Each subsequent configuration inherits from - and can override - the previous one:

ts
import type { xBuildConfig } from '@remotex-labs/xbuild';

import { version } from 'process';
import pkg from './package.json' with { type: 'json' };

const config: Array<xBuildConfig> = [
    {
        declaration: true,
        esbuild: {
            bundle: true,
            minify: true,
            format: 'esm',
            outdir: 'dist/esm',
            target: [ `node${ version.slice(1) }` ],
            platform: 'node',
            packages: 'external',
            sourcemap: true,
            entryPoints: [ 'src/index.ts' ]
        }
    },
    {
        declaration: false,
        noTypeChecker: true,
        esbuild: {
            bundle: true,
            format: 'cjs',
            outdir: 'dist/cjs'
        }
    }
];

export default config;

Properties ​

PropertyTypeDescription
devboolean | Array<string>Build and run entry point(s) in Node.js for development.
watchbooleanRebuild on file changes.
declarationbooleanEmit TypeScript declaration (.d.ts) files.
bundleDeclarationbooleanBundle all declaration files into a single output file.
declarationOutDirstring?Output directory for .d.ts files. Falls back to tsconfig.json's outDir.
moduleTypeOutDirstring?Where to write the generated package.json declaring the module format (see below).
buildOnErrorbooleanContinue the build even if TypeScript errors are present.
noTypeCheckerbooleanSkip TypeScript type checking entirely.
esbuildBuildOptionsCore esbuild options: entry points, bundling, format, target, and so on.
serveServeInterfaceServe the output over HTTP(S). See Serve configuration.
hooksPartial<HooksInterface>?Lifecycle hook functions. See Lifecycle hooks.
defineRecord<string, unknown>Compile-time constants; also drives ifdef.
banner{ [type]: string | (() => string) }?String prepended to every output file (esbuild banner).
footer{ [type]: string | (() => string) }?String appended to every output file (esbuild footer).

moduleTypeOutDir ​

Controls where the generated package.json declaring the module format is written:

  • If format is esm, writes { "type": "module" }
  • If format is cjs, writes { "type": "commonjs" }
ts
{
    esbuild: {
        outdir: 'dist',
        format: 'esm'
    },
    moduleTypeOutDir: 'custom/dist'
}

define ​

Compile-time global constants, ideal for environment flags:

ts
define: {
    'process.env.NODE_ENV': '"development"',
    'API_URL': '"https://api.example.com"'
}

Flags declared here also control ifdef blocks and $$ function stripping.

See also ​

Released under the Mozilla Public License 2.0