This folder contains all of the code for bndl
, along with unit testing.
pnpm add @bndl/lib
build
: Build application for development or production distributionfix:lint
: Fix any lint issues that can be done automaticallytest:lint
: Check lint for both server and site applicationtest:types
: Check types for both server and site applicationtest:components
: Run unit tests
The lib folder contains two pieces the React Hook and the React Component. There is also a custom error exported for reference, see error.
The React Hook exported is useBundle
it leverages useCallback
to cache internal functions. A global variable is also used to cache all bundles loaded.
useBundle
: React hook to load and render a React Component from an independent Rect bundle- Props
path
: URL to bundle to load, can be relative or absolutename
: Exported name of bundle that is loaded in the global scopecomponent
: Loads an exported component from the designated bundle, uses default if nothing is specified
- Returns
isLoading
: Indicates whether current hook loadingdata
: Data used to create a React.Component withReact.createElementerror
<null|Error>: Any internal errors caught
- Props
There are two components that are exported: BundleComponent and DynamicComponent.
BundleComponent
: Returns a React Component that utilizes useBundle under the hood.- Props
path
: URL to bundle to load, can be relative or absolutename
: Exported name of bundle that is loaded in the global scopecomponent
: Loads an exported component from the designated bundle, uses default if nothing is specifiedonError
: Optional error callback if anything internal is caughtLoaderComponent
<React.Component>: Optional custom component for loading state
- Props
DynamicComponent
: A wrapper around React.createElement.
A customer Error class to help identify any issues, and use for testing.
- Properties
message
: Error messagestack
: Stack trace of where error occurred
ESBuild creates the distribution bundles that will be imported when downloading the package. There are two versions created: ESM and CommonJS, the package.json in the root of the repository outlines specifically these two exports.
See build configuration here.
- Environment Variables
BUILD
<development|production>: Determines what environment to build for, defaults to development
For component and unit test, the React version for Testing Library is used. Tests are written in the folders associated with the components they are testing.