@tessin/tcm-boot v1.0.16
TCM boot loader
Bootstrapping code for client (browser) and server (Node.js). The purpose of this code is to allow us to track code dependencies as they are loaded into the process as well as allow us to create isolated runtime environments that can be used to evict.
API
| Module | Function | Arguments |
|---|---|---|
lib/client | clientBootLoader | { index, cache, initialProps, main, externals } |
lib/server | serverBootLoader | { index, cache, initialProps, main } |
lib/instantiate | instantiateBootLoader | { index, cache, initialProps, main } |
Example
The entry point must export a function, like this:
import { EntryPoint } from "@tessin/tcm-boot"
const main: EntryPoint = function(index, cache, initialProps, useRequireHook) {
// <your code goes here>
}
export = mainThis function doesn't have to do anything in particular. It can access the bundle dependencies from the index, cache and initialProps respectively. For more advanced situations you can use useRequireHook to install a custom function that will be used to require module from then on.
| Argument | Description |
|---|---|
index | Module ID to source text (JavaScript) |
cache | Module ID to module instance (loaded) |
initialProps | Any properties passed along with the creation of the bootloader |
useRequireHook | Used to install a require hook |
The cache is only used to pass data dependencies to the boot loader. However, initialized modules from the bootstrapping process will be loaded into cache before main is called.
Client/browser
Code will run as part of the DOMContentLoaded event.
The client boot loader is sanitized to minimize attack surfaces.
Server/Node.js
Code will run as required propagating the return value from the main entry point function as exports.
There are two variants of the server boot loader, serverBootLoader which will return a JavaScript string and instantiateBootLoader which will bootstrap a new CommonJS environment in the current running process.