mini-star

2.1.8 · active · verified Tue Apr 21

mini-star is a robust frontend micro-kernel framework, bundler, and loader designed to help projects implement a plugin-based architecture. It facilitates the independent development and deployment of features as separate plugins. The library, currently at version 2.1.8, supports TypeScript natively and is framework-agnostic, meaning it can be integrated with React, Vue, Angular, jQuery, or other modern web frameworks. Key differentiators include its bundler for building AMD-based plugins, automatic processing of plugin and dependency paths, dynamic asynchronous module loading to optimize project size, and a powerful mechanism for sharing common dependencies across all plugins, reducing boilerplate and bundle size. Unlike `requirejs`, `mini-star` operates at a module level, aligning with modern frontend practices, and it distinguishes itself from micro-frontend solutions like `qiankun` by prioritizing dependency reuse and an isomorphic technology stack rather than isolation for heterogeneous applications. It offers a complete toolchain encompassing CLI, runtime, and bundler functionalities. The project appears to have an active development and maintenance cadence, with recent documentation updates indicating ongoing support.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize `mini-star`, register shared dependencies like React and ReactDOM, and dynamically load a plugin. It shows basic configuration, error handling, and how a plugin's exposed methods can be invoked.

import { MiniStar } from 'mini-star';

interface MyPluginInstance {
  render: (selector: string) => void;
  // ... other methods/properties exposed by the plugin
}

async function initializeMiniStar() {
  const ministar = new MiniStar({
    // Optional: Configure base path for plugins, e.g., for local development or CDN
    base: '/plugins/', 
    // Optional: Global error handler for plugin loading failures
    errorHandler: (error, pluginName) => {
      console.error(`Failed to load plugin ${pluginName}:`, error);
    }
  });

  // Register shared dependencies that plugins might use, preventing duplication
  // This should be done before loading plugins that depend on them.
  ministar.registerShared('react', window.React || require('react'));
  ministar.registerShared('react-dom', window.ReactDOM || require('react-dom'));
  console.log('Shared dependencies registered.');

  try {
    // Load a plugin by its registered name or path
    const myPlugin = await ministar.loadPlugin<MyPluginInstance>('my-plugin-entry');
    console.log('Plugin loaded successfully:', myPlugin);

    // Assume the plugin exports a render function
    if (myPlugin && typeof myPlugin.render === 'function') {
      myPlugin.render('#app-root');
      console.log('Plugin rendered to #app-root');
    }
  } catch (error) {
    console.error('Error during plugin loading or rendering:', error);
  }
}

// Ensure React and ReactDOM are available globally for demonstration if not bundled
// In a real app, these would be proper imports in your host application
(window as any).React = require('react');
(window as any).ReactDOM = require('react-dom');

initializeMiniStar();

view raw JSON →