Build Lifecycle
This page documents the build lifecycle and the internal stages that run during a susee build. All stages are built-in and run automatically as part of the bundling and compilation pipeline.
Lifecycle stages
Susee groups its build work into stages that mirror the lifecycle of the compilation pipeline.
1) Bundling stage (via @suseejs/susee_bundler)
Run inside src/bundler.ts, which calls suseeBundler(entry, root, checks) from @suseejs/susee_bundler. This stage:
- Resolves the dependency tree from the entry file
- Merges dependency and entry content into a single source string
- Runs dependency analysis and lint checks (anonymous exports, default exports, npm-installed verification)
- Emits a warning when the dependency set contains CommonJS modules (suggesting ESM migration)
- The bundled source is cached per entry point inside
@suseejs/susee_bundler
Note: The public
suseeBundle(entry, checkOptions?)API and the CLIbundlecommand both expose this stage directly, returning (or writing) the bundled source string without running compilation.
2) Compiler option resolution
Run inside src/compiler/tsoptions.ts using @suseejs/ts6. This stage:
- Reads the custom
tsconfigFilePathif provided, otherwise finds the roottsconfig.json - Parses the config and produces per-format compiler options (
CommonJS/ES2020module kind) - Falls back to internal defaults if no tsconfig is found
3) Compilation stage (via @suseejs/ts6)
Run inside src/compiler/suseeCompiler.ts. This stage:
- Creates an in-memory
CompilerHostthat serves the bundled source - Detects JSX in the bundled source and validates React/
jsxImportSourceruntime - Adjusts compiler options when JSX is detected (
jsx: ReactJSX,lib: ["dom", "dom.iterable", "esnext"]) - Emits JavaScript (
.mjs/.cjs), declarations (.d.mts/.d.cts), and source maps (.mjs.map/.cjs.map)
4) Post-compile: minification (optional)
Run inside src/helpers/minify.ts. This stage:
- Runs
oxc-minifyover the emitted JavaScript when the entry’sminifyoption is enabled - Falls back to the unminified source on parse failure
- Gated by the per-entry
minifyconfig field or the--minifyCLI flag
5) File output and package.json update
Run inside src/helpers/files.ts. This stage:
- Writes output files (
.mjs/.cjs,.d.mts/.d.cts,.mjs.map/.cjs.map) to the output directory - Updates
package.jsonexport metadata (exports,main,module,types) whenallowUpdatePackageJsonis enabled
Lifecycle order
For each entry point and each requested output format (esm and/or commonjs), susee runs this high-level flow:
- Resolve compiler options (
tsconfigFilePath→ roottsconfig.json→ internal defaults) - Bundle the entry’s dependency tree into a single source string (
@suseejs/susee_bundler) - Detect JSX in the bundled source and adjust compiler options if needed
- Compile the bundled source in-memory (
@suseejs/ts6) — emit JS + declarations + source map - Rename the sourcemap reference (
.js.map→.mjs.map/.cjs.map) - Optionally minify the emitted JS (
oxc-minify, whenminifyis enabled for the entry) - Write output files to the output directory
- Update
package.jsonexport metadata (only whenallowUpdatePackageJson: true)