← Back to Usage Guide Index
This example shows the fastest way to get M7BootStrap running in your project. We’ll initialize the bootstrapper, load a package, and mount its content.
- m7Fetch for package and asset fetching. Repo: https://github.com/linearblade/m7fetch
- A JavaScript environment that supports
import/ES modules (Node 18+, modern browsers).
your-project/
vendor/
m7Bootstrap/
BootStrap.js
m7Fetch/
src/
index.js
index.js
For demonstration, we’ll use a symbolic package reference and a repo definition:
const resources = [
{ resource: "scene:chess", repo: ["/repo"] }
];import Net from "./vendor/m7Fetch/src/index.js";
import BootStrap from "./vendor/m7Bootstrap/BootStrap.js";
// Initialize networking layer and bootstrapper
const net = new Net();
const bootstrap = new BootStrap(net);
// Define package load options
const opts = {
package: { hooks: true } // run package-defined "run" hooks (default: true)
};
// Handlers
const onLoad = [
"#runner.mount", // symbolic reference to a bootstrapper method
(sys, ctx) => console.log("Loaded packages:", ctx)
];
const onError = [
"logFailure",
(sys, ctx) => console.warn("Failed to load:", ctx)
];
// Load the package(s)
const success = await bootstrap.load(resources,{ load:onLoad, error:onError}, opts);
if (!success) {
console.error("Bootstrap failed");
}- Dependency resolution — M7BootStrap builds a dependency graph from resources.
- Parallel fetch — Packages, assets, and modules are retrieved as quickly as possible.
- Mounting — HTML assets are mounted automatically; modules are stored in bootstrap’s registry.
- Hooks — If enabled, any run hooks in packages are executed.
- Handlers — onLoad or onError handlers are run with full context.
await bootstrap.unload(
["scene:chess"], // package ids
["#runner.unmount"], // onDone handlers
["logFailure"], // onError handlers
{ ignoreMissing: true } // options
);This removes the package’s mounted assets and clears modules from the bootstrapper. If you copied modules elsewhere, you’ll need to remove them manually.
- Learn how to configure resources and repos in detail: Package & Repo Specifications
- Explore the full set of lifecycle hooks and event handlers: Hooks & Handlers
- Continue to Core API Overview to learn the primary methods exposed for use