Registry / devops / bit-loader-shimmer

bit-loader-shimmer

JSON →
library1.1.0jsnpmunverified

The `bit-loader-shimmer` package provides a plugin for `bit-bundler`, enabling detailed control over how non-modular or legacy JavaScript modules are integrated into a modern bundler environment. Currently at version 1.1.0, this package allows developers to define 'shims' for specific modules, dictating their file paths, dependencies (imports), and what they expose to other modules or the global scope (exports). This is particularly useful for handling libraries that expect global variables, require a specific load order, or do not conform to CommonJS or ES module patterns. It offers granular configuration options, such as aliasing imports and exports, linking to global objects, and resolving modules by name or direct path. While a specific release cadence isn't published, the 1.x versioning suggests stability. Its key differentiator lies in its comprehensive API for managing the module environment for legacy scripts, bridging the gap between traditional script inclusion and modular bundling, especially within the `bit-bundler` ecosystem.

npm install bit-loader-shimmer
INSTALL
IMPORT
SIG · BIT-LOADER-SHIMMER
B
bit-loader-shimmer
devopsjavascriptv1.1.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

shim
import shim from 'bit-loader-shimmer'
import { shim } from 'bit-loader-shimmer'
The `shim` function is the default export and should typically be imported as such in ESM contexts.
shim
const shim = require('bit-loader-shimmer')
CommonJS environments use `require` to import the default exported `shim` function.
shim
import * as shim from 'bit-loader-shimmer'
This pattern imports the entire module as a namespace object, which can be useful in some bundler configurations or when explicit default import is not desired.

This quickstart demonstrates how to configure `bit-loader-shimmer` to handle legacy libraries like jQuery and Bootstrap, managing their imports, exports, and global interactions within a `bit-bundler` setup.

const shim = require('bit-loader-shimmer'); const path = require('path'); const shimConfig = shim({ // Shim configuration for jQuery, exposing it globally and as an export jquery: { // Use 'name' for module resolution by bit-bundler name: 'jquery/dist/jquery.js', // Define how jQuery exports itself or is made available exports: [{ as: '$', name: 'window.$', global: ['$'] // Expose as global $ variable }, { as: 'jQuery', name: 'window.jQuery', global: ['jQuery'] // Expose as global jQuery variable }] }, // Shim configuration for Bootstrap, which depends on jQuery bootstrap: { // Specify the direct path to the Bootstrap JavaScript file path: path.resolve('./node_modules/bootstrap/dist/js/bootstrap.js'), // Bootstrap expects jQuery to be available, so we import it imports: [{ as: 'jQuery', // Create a local 'jQuery' variable for Bootstrap's scope name: 'jquery' // Refers to the 'jquery' shim defined above }], // If Bootstrap exposes a specific component, e.g., Modal, export it exports: [{ as: 'Modal', name: 'window.bootstrap.Modal', // Assuming it attaches to window.bootstrap global: 'bootstrap.Modal' }] }, // Example for a simple legacy script that might modify the global scope myLegacyScript: { path: './src/legacy-global-modifier.js' // This script runs, and can be ensured to load at a specific time. } }); console.log("Generated shim configuration:\n", JSON.stringify(shimConfig, null, 2)); console.log("\nThis configuration object should be passed to bit-bundler's plugins array."); // Example of how it would be used within bit-bundler (not runnable without bit-bundler setup): // const BitBundler = require('bit-bundler'); // const bundler = new BitBundler({ // src: ['./entry.js'], // dest: './bundle.js', // plugins: [shimConfig] // }); // bundler.bundle().then(() => console.log('Bundled with shims!'));
Debug
Known issues
gotchaIncorrectly configured `imports` or `exports` can lead to runtime errors, undefined globals, or modules not receiving their expected dependencies. Complex interactions with global objects require careful setup.
fix
Carefully trace expected global names and module dependencies. Use the `as` property for local aliases within the shimmed module's scope and `global` for managing properties on the `window` or global object. Validate loading order and variable availability.
affects: >=1.0.0
gotchaShimming large, monolithic libraries with many internal dependencies can be brittle and difficult to maintain. The shim configuration might not fully capture the library's internal loading mechanisms.
fix
Prioritize using modern, modular versions of libraries when available. Use shimming primarily for smaller, isolated legacy scripts, or to bridge specific global dependencies for otherwise modular code. Consider refactoring legacy code if shimming becomes overly complex.
affects: >=1.0.0
gotchaRelative paths specified in the `path` option are resolved relative to the bit-bundler configuration file, not necessarily the current working directory or the shimmed module itself.
fix
Always use `path.resolve()` with `__dirname` or absolute paths for clarity and reliability, especially when dealing with module paths that might be ambiguous, or use the `name` option for modules resolvable via npm or similar registries.
affects: >=1.0.0
Errors
Common errors & fixes
ReferenceError: $ is not defined
A shimmed module (e.g., Bootstrap) expects jQuery's '$' global to be available, but the jQuery shim either wasn't processed or didn't correctly expose '$' to the global scope or to subsequent shims.
fix
Ensure the shim for jQuery (or similar dependency) is loaded before the dependent module and that its `exports` configuration correctly includes `global: ['$']` (and potentially `name: 'window.$'`) to make the variable available.
Module not found: Can't resolve 'my-library/dist/my-file.js'
The `path` or `name` property within a shim configuration points to an incorrect or non-existent file or an unresolvable module identifier.
fix
Verify the `path` property contains the correct, absolute, or relative-to-config-file path to the shimmed file. If using `name`, ensure the module is installed and its main entry point or sub-path is correctly specified according to Node.js resolution rules.
Error: Cannot read properties of undefined (reading 'Modal')
A downstream module attempts to import a named export (e.g., `Modal`) from a shimmed module, but the shim's `exports` configuration did not correctly define and expose that specific property.
fix
Review the `exports` array for the shimmed module, ensuring that the `as`, `name`, and `global` properties correctly map the internal variable or global object property to the desired export name.
Upgrade
Version history
1.1.0latest on npm
Audit
Dependencies
bit-bundlerrequiredThis package is a plugin specifically designed for use with bit-bundler.
Agent activity
19 hits · last 30 days
node
14
OpenAI (training)
1
Resources
bit-loader-shimmer — npm install bit-loader-shimmer · libregistry