0.3.11 • Published 1 year ago

dynamic-remotes-plugin v0.3.11

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

dynamic-remotes-plugin

npm

Compatible with external-remotes-plugin plugin API

Provide hook, dynamic remote url

  • options.resolvePath is required
  • options.inject is not required

Host webpack.config

const DynamicRemotesPlugin = require("dynamic-remotes-plugin")
const config = {
   ...otherConfigs
  plugins: [
    new ModuleFederationPlugin({
      name: "app1",
      remotes: {
        app2: "app2@^1.0.0?a=1"
      }
    }).
    new DynamicRemotesPlugin({
      // This hook will take effect on both the node side and the browser side
      resolvePath(request) {
        const {name, version, entry, query} = request
        function join(start, str) {
          return (str && `${start}${str}`) || ""
        }
        return `https://unpkg.com/${name}${join("@", version)}${join("/", entry)}/remoteEntry.js${join("?", query)}`
      },
      // This hook only takes effect in the browser
      // The following demonstrates how to use semverhook to proxy a package to the local
      // https://github.com/wpmjs/wpmjs/tree/main/packages/semverhook
      inject(semverhook) {
        return `
        // mock dev
        window.isDev = true
        ${semverhook}.on("resolvePath", request => {
          if (window.isDev && request.name === "app2") {
            return "https://localhost:3000/remoteEntry.js"
          }
        })
        `
      }
    }),
  ]
}
0.3.11

1 year ago

0.3.10

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.8

1 year ago

0.2.7

1 year ago

0.2.6

1 year ago

0.2.5

1 year ago

0.2.4

1 year ago

0.2.3

1 year ago

0.2.2

1 year ago

0.2.1

1 year ago

0.2.0

1 year ago

0.1.5

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago