diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e884fef --- /dev/null +++ b/.gitignore @@ -0,0 +1,306 @@ +# dependencies +/node_modules + +# production +/dist + +# misc +.DS_Store +.vscode +.ideal + +npm-debug.log* +yarn-debug.log* +yarn-error.log* +yarn.lock +package-lock.json + + +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + + +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* + + + +# Built application files +*.apk +*.ap_ +*.aab + +# Files for the ART/Dalvik VM +*.dex + +# Java class files +*.class + +# Generated files +bin/ +gen/ +out/ +release/ + +# Gradle files +.gradle/ +build/ + +# Local configuration file (sdk path, etc) +local.properties + +# Proguard folder generated by Eclipse +proguard/ + +# Log Files +*.log + +# Android Studio Navigation editor temp files +.navigation/ + +# Android Studio captures folder +captures/ + +# IntelliJ +*.iml +.idea/workspace.xml +.idea/tasks.xml +.idea/gradle.xml +.idea/assetWizardSettings.xml +.idea/dictionaries +.idea/libraries +# Android Studio 3 in .gitignore file. +.idea/caches +.idea/modules.xml +# Comment next line if keeping position of elements in Navigation Editor is relevant for you +.idea/navEditor.xml + +# Keystore files +# Uncomment the following lines if you do not want to check your keystore files in. +#*.jks +#*.keystore + +# External native build folder generated in Android Studio 2.2 and later +.externalNativeBuild + +# Google Services (e.g. APIs or Firebase) +# google-services.json + +# Freeline +freeline.py +freeline/ +freeline_project_description.json + +# fastlane +fastlane/report.xml +fastlane/Preview.html +fastlane/screenshots +fastlane/test_output +fastlane/readme.md + +# Version control +vcs.xml + +# lint +lint/intermediates/ +lint/generated/ +lint/outputs/ +lint/tmp/ +# lint/reports/ + + +# Xcode +# +# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore + +## Build generated +build/ +DerivedData/ + +## Various settings +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 +xcuserdata/ + +## Other +*.moved-aside +*.xccheckout +*.xcscmblueprint + +## Obj-C/Swift specific +*.hmap +*.ipa +*.dSYM.zip +*.dSYM + +# CocoaPods +# +# We recommend against adding the Pods directory to your .gitignore. However +# you should judge for yourself, the pros and cons are mentioned at: +# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control +# +# Pods/ +# +# Add this line if you want to avoid checking in source code from the Xcode workspace +# *.xcworkspace + +# Carthage +# +# Add this line if you want to avoid checking in source code from Carthage dependencies. +# Carthage/Checkouts + +Carthage/Build + +# fastlane +# +# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the +# screenshots whenever they are needed. +# For more information about the recommended setup visit: +# https://docs.fastlane.tools/best-practices/source-control/#source-control + +fastlane/report.xml +fastlane/Preview.html +fastlane/screenshots/**/*.png +fastlane/test_output + +# Code Injection +# +# After new code Injection tools there's a generated folder /iOSInjectionProject +# https://github.com/johnno1962/injectionforxcode + +iOSInjectionProject/ + + +# Xcode +# +# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore + +## Build generated +build/ +DerivedData/ + +## Various settings +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 +xcuserdata/ + +## Other +*.moved-aside +*.xccheckout +*.xcscmblueprint + +## Obj-C/Swift specific +*.hmap +*.ipa +*.dSYM.zip +*.dSYM + +## Playgrounds +timeline.xctimeline +playground.xcworkspace + +# Swift Package Manager +# +# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. +# Packages/ +# Package.pins +# Package.resolved +.build/ + +# CocoaPods +# +# We recommend against adding the Pods directory to your .gitignore. However +# you should judge for yourself, the pros and cons are mentioned at: +# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control +# +# Pods/ +# +# Add this line if you want to avoid checking in source code from the Xcode workspace +# *.xcworkspace + +# Carthage +# +# Add this line if you want to avoid checking in source code from Carthage dependencies. +# Carthage/Checkouts + +Carthage/Build + +# Accio dependency management +Dependencies/ +.accio/ + +# fastlane +# +# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the +# screenshots whenever they are needed. +# For more information about the recommended setup visit: +# https://docs.fastlane.tools/best-practices/source-control/#source-control + +fastlane/report.xml +fastlane/Preview.html +fastlane/screenshots/**/*.png +fastlane/test_output + +# Code Injection +# +# After new code Injection tools there's a generated folder /iOSInjectionProject +# https://github.com/johnno1962/injectionforxcode + +iOSInjectionProject/ \ No newline at end of file diff --git a/JSBridgeH5/.gitignore b/JSBridgeH5/.gitignore new file mode 100644 index 0000000..c151b98 --- /dev/null +++ b/JSBridgeH5/.gitignore @@ -0,0 +1,16 @@ +# dependencies +/node_modules + +# production +/dist + +# misc +.DS_Store +.vscode +.ideal + +npm-debug.log* +yarn-debug.log* +yarn-error.log* +yarn.lock +package-lock.json \ No newline at end of file diff --git a/JSBridgeH5/README.md b/JSBridgeH5/README.md new file mode 100644 index 0000000..b8fbe4c --- /dev/null +++ b/JSBridgeH5/README.md @@ -0,0 +1,45 @@ +# JSBridgeH5 +`JSBridge` 实例中 `H5` 端代码实现。 + +此项目使用 react 进行编写,但是关于 react 的代码不多,其中关于 jsbridge 使用的代码在任意项目或者框架中均可使用。 + +代码中有详细注释。 + + +## 下载项目 +``` bash +git clone https://github.com/beichensky/jsbridge-example.git +``` + +## 安装插件 +``` bash +# 打开 JSBridgeH5 项目 +cd JSBridgeH5 + +# 安装依赖 +npm install +``` + + +## 运行项目 +``` bash +npm run start +``` + +打开浏览器,输入:`localhost:8000` 查看项目运行效果。 + +运行项目后,才能在原生应用中展示,否则移动端 Webview 加载不出来页面。请记得在将当前的 ip 地址和端口替换到移动端 url 上。 + + + +## 项目打包 +``` bash +npm run build +``` + +新增 `dist` 目录,里面是打包好的项目代码 + + + +## 更多 +关于项目的更多介绍请查看我的博客:[使用 JSBridge 与原生 IOS、Android 进行交互(含H5、Android、IOS端代码,附 Demo)]() diff --git a/JSBridgeH5/babel.config.js b/JSBridgeH5/babel.config.js new file mode 100644 index 0000000..21b576f --- /dev/null +++ b/JSBridgeH5/babel.config.js @@ -0,0 +1,69 @@ +module.exports = (api) => { + api.cache(true); + + return { + presets: [ + "@babel/preset-env", + "@babel/preset-react" + ], + plugins: [ + [ + "@babel/plugin-proposal-decorators", + { + "legacy": true + } + ], + [ + "import", + { + "libraryName": "antd", + "style": true + } + ], + [ + "@babel/plugin-transform-runtime", + { + "corejs": 2 + } + ], + [ + "@babel/plugin-proposal-class-properties", + { + "loose": true + } + ], + "@babel/plugin-syntax-dynamic-import", + // "@babel/plugin-syntax-import-meta", + // 可以用 const ex = "before + // after"; 这种方式编写字符串 + // "@babel/plugin-proposal-json-strings", + // 可以使用 generate 语法 + // "@babel/plugin-proposal-function-sent", + // 可以使用 export * 这种命名空间的方式导出模块 + "@babel/plugin-proposal-export-namespace-from", + // 可以使用数字分离器书写数字 + // "@babel/plugin-proposal-numeric-separator" + // 可以使用异常抛出表达式, + "@babel/plugin-proposal-throw-expressions", + // 默认导出 + "@babel/plugin-proposal-export-default-from", + // 可以使用逻辑赋值运算符 + "@babel/plugin-proposal-logical-assignment-operators", + // 可以使用可选链的方式访问深层嵌套的属性或者函数 ?. + "@babel/plugin-proposal-optional-chaining", + // 可以使用管道运算符 |> + [ + "@babel/plugin-proposal-pipeline-operator", + { + "proposal": "minimal" + } + ], + // 可以使用空值合并语法 ?? + "@babel/plugin-proposal-nullish-coalescing-operator", + // 可以使用 do 表达式(可以认为是三元运算符的复杂版本) + "@babel/plugin-proposal-do-expressions", + // 可以使用功能绑定语法 obj::func + "@babel/plugin-proposal-function-bind" + ] + } +} diff --git a/JSBridgeH5/package.json b/JSBridgeH5/package.json new file mode 100644 index 0000000..5864283 --- /dev/null +++ b/JSBridgeH5/package.json @@ -0,0 +1,64 @@ +{ + "name": "jsbridge-h5", + "version": "1.0.0", + "description": "", + "private": true, + "scripts": { + "start": "webpack-dev-server --config webpack/webpack.config.dev.js", + "build": "webpack --config webpack/webpack.config.prod.js" + }, + "keywords": [], + "author": "", + "license": "ISC", + "devDependencies": { + "@babel/core": "^7.0.0", + "@babel/plugin-proposal-class-properties": "^7.0.0", + "@babel/plugin-proposal-decorators": "^7.0.0", + "@babel/plugin-proposal-do-expressions": "^7.0.0", + "@babel/plugin-proposal-export-default-from": "^7.0.0", + "@babel/plugin-proposal-export-namespace-from": "^7.0.0", + "@babel/plugin-proposal-function-bind": "^7.0.0", + "@babel/plugin-proposal-logical-assignment-operators": "^7.0.0", + "@babel/plugin-proposal-nullish-coalescing-operator": "^7.0.0", + "@babel/plugin-proposal-optional-chaining": "^7.0.0", + "@babel/plugin-proposal-pipeline-operator": "^7.0.0", + "@babel/plugin-proposal-throw-expressions": "^7.0.0", + "@babel/plugin-syntax-dynamic-import": "^7.0.0", + "@babel/plugin-transform-runtime": "^7.0.0", + "@babel/preset-env": "^7.0.0", + "@babel/preset-react": "^7.0.0", + "@babel/runtime-corejs2": "^7.0.0", + "autoprefixer": "^9.5.1", + "babel-loader": "^8.0.0", + "babel-plugin-import": "^1.11.0", + "clean-webpack-plugin": "^2.0.1", + "css-loader": "^2.1.1", + "csv-loader": "^3.0.2", + "file-loader": "^3.0.1", + "friendly-errors-webpack-plugin": "^1.7.0", + "html-loader": "^0.5.5", + "html-webpack-plugin": "^3.2.0", + "less": "^3.9.0", + "less-loader": "^4.1.0", + "markdown-loader": "^5.0.0", + "mini-css-extract-plugin": "^0.5.0", + "optimize-css-assets-webpack-plugin": "^5.0.1", + "postcss-loader": "^3.0.0", + "style-loader": "^0.23.1", + "uglifyjs-webpack-plugin": "^2.1.2", + "webpack": "^4.29.6", + "webpack-cli": "^3.3.0", + "webpack-dev-server": "^3.1.4", + "webpack-merge": "^4.2.1", + "xml-loader": "^1.2.1" + }, + "dependencies": { + "antd": "^3.16.2", + "js-cookie": "^2.2.0", + "moment": "^2.24.0", + "prop-types": "^15.7.2", + "qs": "^6.7.0", + "react": "^16.8.6", + "react-dom": "^16.8.6" + } +} diff --git a/JSBridgeH5/public/favicon.ico b/JSBridgeH5/public/favicon.ico new file mode 100644 index 0000000..a11777c Binary files /dev/null and b/JSBridgeH5/public/favicon.ico differ diff --git a/JSBridgeH5/public/index.html b/JSBridgeH5/public/index.html new file mode 100644 index 0000000..7a4509e --- /dev/null +++ b/JSBridgeH5/public/index.html @@ -0,0 +1,12 @@ + + +
+ + + +