New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

vanilla-native-federation

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vanilla-native-federation

Check the full description of native-federation on [@softarc/native-federation](https://www.npmjs.com/package/@softarc/native-federation). This library is specifically made for stateful models that require a small library to (lazy) load micro frontends or

  • 0.1.1
  • unpublished
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
9
decreased by-90.32%
Maintainers
1
Weekly downloads
 
Created
Source

vanilla-native-federation

Check the full description of native-federation on @softarc/native-federation. This library is specifically made for stateful models that require a small library to (lazy) load micro frontends or webcomponents on frameworkless webpages using native-federation (e.g. PHP, Ruby or Java applications).

Simple usage:

loader.ts

import { initFederation } from 'vanilla-native-federation';

(() => {
    const manifest = {
        "mfe": "http://localhost:3000/remoteEntry.json"
    }
    initFederation(manifest)
        .then(({load, importMap}) => Promise.all([
            load('mfe1', './Component'),
            load('mfe2', './Component'),
        ]))
        .catch(console.error);
})();

usage using custom events:

loader.ts

import { initFederation } from 'vanilla-native-federation';

(() => {
    const manifest = {
        "mfe": "http://localhost:3000/remoteEntry.json"
    }
    initFederation(manifest)
        .then(({load, importMap}) => {
            console.log("importMap: ", importMap);
            window.dispatchEvent(new CustomEvent("mfe-loader-available", {detail: {load}}));
        })
})();

your-shell.html

<script type="module" src="loader.js"></script>

<script>
    window.addEventListener('mfe-loader-available', (e) => {
        Promise.all([
            e.detail.load('mfe1', './Component'),
            e.detail.load('mfe2', './Component'),
        ]).catch(console.error);
    }, {once: true});
</script>    

Usage with discovery:

This library also contains the implementation for micro frontend discovery. Convenient for micro frontend architectures that require a more robust and detailed discovery mechanism:

loader.ts

import { initFederationWithDiscovery } from 'vanilla-native-federation';

(() => {
    const myDiscoveryUrl = "http://localhost:3000";
    initFederationWithDiscovery(myDiscoveryUrl)
        .then(({load, discovery, importMap}) => {
            console.log("discovery: ", discovery);
            console.log("importMap: ", importMap);
            window.dispatchEvent(new CustomEvent("mfe-loader-available", {detail: {load}}));
        })
})();

your-shell.html

<script type="module" src="loader.js"></script>

<script>
    window.addEventListener('mfe-loader-available', (e) => {
        Promise.all([
            e.detail.load('mfe1', './Component'),
            e.detail.load('mfe2', './Component'),
        ]).catch(console.error);
    }, {once: true});
</script>    

Expected format from discovery service:

{
  "schema": "https://github.com/awslabs/frontend-discovery/blob/main/schema/v1-pre.json",
  "microFrontends": {
    "mfe1": [
      {
        "url": "http://localhost:3001/mfe1.js",
        "metadata": {
          "integrity": "CHECKSUM",
          "version": "1.0.0"
        },
        "deployment": {
          "traffic": 100,
          "default": true
        },
        "extras": {
          "nativefederation": {
            "remoteEntry": "http://localhost:3001/remoteEntry.json",
            "key": "./Component",
          }
        }
      }
    ],
    "mfe2": [
      {
        "url": "http://localhost:3002/mfe1.js",
        "metadata": {
          "integrity": "CHECKSUM",
          "version": "1.0.0"
        },
        "deployment": {
          "traffic": 100,
          "default": true
        },
        "extras": {
          "nativefederation": {
            "remoteEntry": "http://localhost:3002/remoteEntry.json",
            "key": "./Component",
          }
        }
      }
    ]
  }
}

Keywords

FAQs

Package last updated on 11 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc