webpack-jsbridge-plugin

1.0.2 • Public • Published

webpack-jsbridge-plugin

A webpack plugin to proxy jsBridge request on JSBridge Server, then you can develop on pc browser without real phones.

Usage

// vue.config.js
const JSBridgePlugin = require("webpack-jsbridge-plugin");

module.exports = defineConfig({
  configureWebpack: {
    plugins: [
      new JSBridgePlugin({
        port: 3300,
        origin: ["http://192.168.13.115:8080"],
      }),
    ],
  },
});

Attention 🔊

In this plugin, the following JavaScript APIs are exposed for both Android and iOS:

call app sdk:

window.androidJS.nativeMethod // android

window.webkit.messageHandlers.nativeObject.postMessage // ios

sdk callback:

window.receiveMessage

If you define other methods, you will need to customize some methods to override them:

// override mock, 通过 inject 注入
window.youSDKMethod = (arg1, arg2) => {
  const data = { arg1, arg2 };
  return window.$jsBridge.invoke(data);
};

window.youSDKCallback = (arg1, arg2)=>{
  onst data = { arg1, arg2 };
  window.receiveMessage(data)
}
// override jsbridge, 通过 server public 覆盖
window.$jsBridge.invoke = (data) => {
  const { arg1, arg2 } = data;
  return window.youSDKMethod(arg1, arg2);
};

window.receiveMessage = (data) => {
  const { arg1, arg2 } = data;
  window.youSDKCallback(arg1, arg2);
};

Readme

Keywords

Package Sidebar

Install

npm i webpack-jsbridge-plugin

Weekly Downloads

2

Version

1.0.2

License

MIT

Unpacked Size

1.07 MB

Total Files

17

Last publish

Collaborators

  • eminoda