0.3.11 • Published 3 years ago

dynamic-remotes-plugin v0.3.11

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years 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

3 years ago

0.3.10

3 years ago

0.3.9

3 years ago

0.3.8

3 years ago

0.3.7

3 years ago

0.3.6

3 years ago

0.3.5

3 years ago

0.3.4

3 years ago

0.3.3

3 years ago

0.3.2

3 years ago

0.3.1

3 years ago

0.3.0

3 years ago

0.2.8

3 years ago

0.2.7

3 years ago

0.2.6

3 years ago

0.2.5

3 years ago

0.2.4

3 years ago

0.2.3

3 years ago

0.2.2

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.1.5

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago