Initialization
BareMetal.init(config)
BareMetal exports its core engine as a global configuration object. Initializes the engine, sets up the Router, and binds global configurations.
Importing & Auto-Wrapping JS Modules
BareMetal strictly uses ES Modules (type: "module"). When navigating to a new page, the engine dynamically imports the scripts defined in your loader({...}) configuration.
By default, dynamically imported modules are expected to export a mount(context) function. However, if you are working with plain JavaScript files that don't explicitly export a mount function, BareMetal's built-in auto-wrapper will handle it.
When autoWrap: true is enabled (which is the default), the engine fetches the script and automatically wraps the content inside a mount function, injecting the state context for you:
Manual Module Wrapping
For full control (and to avoid the overhead of auto-wrapping), you can manually export the mount function. This allows you to safely subscribe to state changes, initialize UI bindings, and return a destroy() function for garbage collection when the user navigates away.
Importing Modules via Loader
Once your module is ready, you tell the engine to load it on specific pages by calling loader({...}) in the HTML:
Bypassing the SPA Router
If you have internal links that you do not want the engine to intercept (e.g., links that trigger server-side redirects, file downloads, or SSO authentication), you can add the data-baremetal="ignore" attribute to the anchor tag. This forces the browser to perform a native, hard navigation.
Configuration Reference
BareMetal exposes several powerful configuration options to control module caching, page transitions, and DOM virtualization.
Read Full Configuration Guide