How to build ESM Views
ESM views are built with the modular build command. The default behaviour when building an ESM view is:
- All the non-local imports in the package’ssrcdirectory are extracted and matched with their version in the package’spackage.jsonor thepackage.jsonin the repository root and with their exact version in the repo’s lockfile.
- The main entrypoint (as defined in the ESM view’s package.json’smainfield) and its local imports are bundled in a single file.
- All the importstatements to non-local dependencies encountered in the process are rewritten toimportfrom an external ESM CDN (by default https://www.skypack.dev/), using the versions extracted in step 1. By default, versions extracted frompackage.jsonwill be used, but users can customize the rewrite template to use versions from the lockfile instead.
- All the local CSS is bundled in a single file.
- The distdirectory is generated, containing:- The js file
- The css file
- A package manifest (package.json) file containing:- The location of the js bundle ("module"field)
- The location of the css bundle ("style"field)
- An object with the whole set of dependencies and their version ranges ("dependencies"field)
- An array of bundled dependencies (bundledDependenciesfield)
 
- The location of the js bundle (
- A synthetically generated index.htmlfile, linking the trampoline file and the css bundle. This file is included in thedistdirectory of the esm-view.
- A synthetically generated trampoline file (_trampoline.js), dynamicallyimporting the js bundle andReact.rendering its default export to a#rootdiv. This file is included in thedist/static/jsdirectory of the esm-view
 
The ESM view build result can either be dynamically imported from a host application, (including the css bundle) or served statically as a standalone application (for example, using modular serve or from a web server).