2.0.1-latest.1 • Published 6 months ago

universal-module-federation-plugin v2.0.1-latest.1

Weekly downloads
-
License
ISC
Repository
github
Last release
6 months ago

universal-module-federation-plugin

This is currently version 2.0 documentation, v1 is here

npm 中文文档

Keep the original API of module-federation, support the integration of various module specifications

Allows you to control all the processes of each dependency by yourself

try online

Table of contents

UmdPlugin examles

Allow module-federation to use umd module, umd dependencies can be obtained from shareScopes or remotes

// webpack.config.js
const {UmdPlugin} = require("universal-module-federation-plugin")

module.exports = {
    plugins: [
        new ModuleFederationPlugin({
          name: 'app3',
          filename: 'remoteEntry.js',
          remotes: {
            app2: "app2@http://localhost:9002/remoteEntry.js",
          },
          exposes: {
            './App': './src/App',
          },
          shared: { react: { singleton: true }, 'react-dom': { singleton: true } },
        }),
        new UmdPlugin({
          // The matched remotes are loaded in umd mode
          remotes: {
            "react-router": "https://unpkg.com/react-router@6.4.3/dist/umd/react-router.production.min.js",
            "@remix-run/router": "https://unpkg.com/@remix-run/router@1.0.3/dist/router.umd.min.js"
          }
        }),
        new UmdPlugin({
          // ...
          // Can be used multiple times
        })   
    ]
}

UmdPlugin API

optionsdescinterfacedefaultexamles
remotesumd remotes{ remoteKey: "{global}@{url}" }{}string>
workerFilesweb worker file path[]/.?worker.js$/

delegate modules

Reference from delegate-modulesnot the official warehouse

// webpack.config.js
const {DelegateModulesPlugin} = require("universal-module-federation-plugin")

module.exports = {
    plugins: [
        new ModuleFederationPlugin({
          shared: { react: { singleton: true } },
        }),
        new DelegateModulesPlugin({
            remotes: {
                test1: "internal ./src/remote-delegate.js?remote=test1@http://localhost:9000/remoteEntry.js"
            }
        })
    ]
}
// src/remote-delegate.js
module.exports = new Promise((resolve, reject) => {
  const currentRequest = new URL(__resourceQuery, __webpack_base_uri__).searchParams.get("remote");
  const [global, url] = currentRequest.split('@');
  const __webpack_error__ = new Error()
  __webpack_require__.l(
    url,
    function (event) {
      if (typeof window[global] !== 'undefined') return resolve(window[global]);
      var realSrc = event && event.target && event.target.src;
      __webpack_error__.message = 'Loading script failed.\\n(' + event.message + ': ' + realSrc + ')';
      __webpack_error__.name = 'ScriptExternalLoadError';
      __webpack_error__.stack = event.stack;
      reject(__webpack_error__);
    },
    global,
  );
})

UniversalModuleFederationPlugin examles

If you have your own module specification, you can use UniversalModuleFederationPlugin to integrate it.

UniversalModuleFederationPlugin Exposes some hooks to customize the loading behavior of remote control

// webpack.config.js
const {UniversalModuleFederationPlugin} = require("universal-module-federation-plugin")

plugins: [
    new UniversalModuleFederationPlugin({
      remotes: {
        app1: function (){
          return Promise.resolve({
            init() {},
            async get(modulePath) {
                return function () {
                    return ({"./App1": "./App1", "./App2": "./App2"})[modulePath]
                }
            }
          })
        }
      },
    })
]
// main.js
import App1 from "app1/App1"
import App2 from "app1/App2"
console.log(App1, App2)
2.0.1-latest.1

6 months ago

1.0.10-beta.0

8 months ago

1.0.9

10 months ago

1.0.8

10 months ago

1.0.7

10 months ago

1.0.6

10 months ago

2.0.1

8 months ago

2.0.0

8 months ago

2.0.0-beta.2

8 months ago

2.0.0-beta.1

8 months ago

2.0.0-beta.0

8 months ago

2.0.0-beta.6

8 months ago

2.0.0-beta.5

8 months ago

2.0.0-beta.4

8 months ago

2.0.0-beta.3

8 months ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago

0.4.16

1 year ago

0.4.15

1 year ago

0.4.14

1 year ago

0.4.13

1 year ago

0.4.11

1 year ago

0.4.10

1 year ago

0.4.9

1 year ago

0.4.8

1 year ago

0.4.7

1 year ago

0.4.3

1 year ago

0.4.2

1 year ago

0.4.1

1 year ago

0.4.0

1 year ago

0.3.9-beta.1

1 year ago

0.3.9

1 year ago

0.3.8

1 year ago

0.3.7

1 year ago

0.3.6

1 year ago

0.3.5

1 year ago

0.3.4

1 year ago

0.3.3

1 year ago

0.3.2

1 year ago

0.3.1

1 year ago

0.3.0

1 year ago

0.2.0

1 year ago

0.2.14

1 year ago

0.1.14

1 year ago

0.1.13

1 year ago

0.1.12

1 year ago

0.1.11

1 year ago

0.1.10

1 year ago

0.1.9

1 year ago

0.1.8

1 year ago

0.1.7

1 year ago

0.1.6

1 year ago

0.1.5

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago