Documentation menu

Configure a build

On this page
Guides0.1.0-alpha.36

Keep build choices in maligator.build.ts at the project root. The CLI evaluates this trusted TypeScript on every invocation and rejects unknown or invalid fields.

Create a configuration

maligator.build.ts
import { defineBuild } from "@maligator/cli";

export default defineBuild({
	entry: "src/index.ts",
	outputName: "my-app",
});

defineBuild preserves the inferred type. Validation happens when the CLI loads the config. Ordinary variables, functions, conditions, and environment reads are allowed. The supported package import is defineBuild; do not import arbitrary helper modules into this file.

shell
maligator run
maligator build src/other.ts --config maligator.build.ts --production

Run these commands from the project root. Create src/other.ts to try the second command. An explicit entry overrides config.entry. --config resolves from the working directory. Without a config, an explicit entry uses product defaults.

Select features and host APIs

Use supported Web APIs and node: or maligator: modules directly. Maligator chooses the host behavior from the APIs the optimized program retains. Node API use selects Node and Web behavior. Web API use alone selects Web behavior. A program that needs neither runs without either host personality.

By default, an unhandled promise rejection is reported. It exits with status 1 under the Node personality. With the Web personality or no personality, the rejection alone leaves the exit status at 0.

Engine choices apply to the application and its workers. Each image records its eval and RegExp policies. RegExp is enabled by default. Eval, Realm support, Temporal, and Intl are opt-in. engine.eval: true embeds the runtime compiler for eval, function constructors, and ShadowRealm.evaluate when engine.realms is enabled. The embedded compiler needs RegExp, so keep engine.regexp enabled when using runtime eval. "compile-check" rejects statically visible dynamic compilation calls and keeps runtime compilation disabled.

Production builds link language and host components by use, including the RegExp matcher, Unicode normalization, Temporal, Intl services, TLS, and compression. They also link Ada and the C++ runtime when a retained API needs the URL parser. Shared runners and the GNU linker fallback include Ada so they can resolve additional references. See the native build reference.

Reflective access such as Object.keys(globalThis) or globalThis[name] keeps globals that the compiler cannot rule out. Enabling runtime compilation also retains global APIs such as URL and Buffer, and the allowed language components, even if the entry only calls ShadowRealm.evaluate. A ShadowRealm evaluates source against its own global object.

Code from new Function, indirect eval such as (0, eval)(source), and the other function constructors runs as global code, so with locked primordials and without realms the rest of the program keeps its whole-program optimizations. A direct eval(source) call can read and assign the bindings in scope at the call and call what they hold, which in a CommonJS module include module, exports and require; the build treats those values as reachable from unseen code and keeps optimizing everything else, such as other modules and functions the call cannot see. CommonJS modules compile as strict code, so a direct eval's var declarations stay inside the eval. A script entry that shares its top-level declarations with global code makes the build optimize the whole program as open to unseen code.

The configuration reference lists each default and interaction. Compatibility lists supported Web and Node APIs.

Replace a module specifier

maligator.build.ts
import { defineBuild } from "@maligator/cli";

export default defineBuild({
	entry: "src/index.ts",
	modules: { aliases: { "app-store": "./src/store.ts" } },
});

Package exports match the conditions maligator and node, the importing syntax’s import or require condition, and default. Set modules.conditions to replace the leading conditions.

Aliases replace exact specifiers before resolution. They are not prefix mappings or TypeScript paths configuration. Create the replacement module before building.

Check a configuration failure

For config file not found, verify the working directory and --config path. For an unknown field, check the full field path in the diagnostic against the reference. Locale-data filtering is not implemented: engine.intl.languages must remain empty.

Assets are declared in source; follow Embed files. See Build for production for target and artifact options.

Maligator 0.1.0-alpha.36 · Experimental · Source 6af07bd09681
Edit this page · Compatibility

Search guides and API reference.

Browse the API · Troubleshooting