esdev build

Shell
esdev build server.ts                          # → dist/server.js
esdev build src/app.ts --out=dist/app.js --minify

One entry, one file, ES modules out. runtime:* imports are left for the runtime to serve, and CommonJS dependencies are converted on the way in.

The CommonJS answer

esrun runs ES modules only, while a large share of npm still ships CommonJS. The bundler converts CJS to ESM on the developer's machine so the deployed artifact remains the text that was reviewed:

Shell
esdev build server.js         # a CJS dependency goes in
esrun dist/server.js          # ordinary ESM comes out

A shorter deploy line

An unbundled program needs --allow-imports, because the loader walks node_modules at runtime. A bundle has no imports left to resolve:

Shell
esrun --allow-imports --allow-listen=8080 app.js  # unbundled
esrun --allow-listen=8080 dist/app.js             # bundled

The build is a security step, not only a packaging one.

Options

Flag
--out=<file>Where to write it (default dist/<entry>.js)
--minifyMinify the output
--conditions=<list>Extra exports conditions, comma-separated; these add to import, default, worker
--define=<name>=<value>Replace a name at build time; process.env.NODE_ENV defaults to "production"
--alias=<name>=<to>Rewrite a specifier before it resolves; repeatable
--sourcemap[=<kind>]A .map beside the output, or =inline, or =hidden

What the application build guarantees

runtime:* stays externalIt is served by the runtime and has no file behind it.
ESM outputThe runtime has no other module system.
process.env.NODE_ENV is definedPackages branch on it before doing anything, and there is no ambient process global.
The worker condition is assertedPackages can select their Web-API build.

--conditions adds rather than replaces, so asking for one more cannot silently cost the worker condition. A dynamic import() emits a content-hashed chunk beside the entry.

Source maps

Shell
esdev build src/server.ts --out=dist/server.js --sourcemap

Source maps are off unless asked. The available forms are:

OptionResult
--sourcemapA .map beside the output, pointed at by the bundle
--sourcemap=inlineA data URL in the file itself
--sourcemap=hiddenWritten, with nothing pointing at it — useful for an error reporter
"sourcemap": trueThe same setting per target in esdev.json; "inline", "hidden" and false are also supported

esrun remaps printed stack traces through the map, while error.stack inside the program remains the engine's original value.

Not yet

Watching a build, and ?raw / ?url suffixes on an import.

Choose a focused guide

  • Project buildsesdev.json, multiple targets, aliases, environment values, plugins and safe output replacement.

  • Browser builds — HTML entries, imported assets, stylesheets and CSS Modules.

  • Library builds--lib, declarations and CommonJS output.

Last updated on
Edit this page