1. 程式人生 > >react-native打離線bundle包

react-native打離線bundle包

Android

打包命令:

eact-native bundle

Options:

–entry-file Path to the root JS file, either absolute or relative to JS root [required]

–platform Either “iOS” or “Android

–transformer Specify a custom transformer to be used (absolute path) [default: “/Users/babytree-mbp13/projects/xcodeProjects/AwesomeProject/node_modules/

React-native/packager/transformer.js”]

–dev If false, warnings are disabled and the bundle is minified [default: true]

–prepack If true, the output bundle will use the Prepack format. [default: false]

–bridge-config File name of a a JSON export of __fbBatchedBridgeConfig. Used by Prepack. Ex. ./bridgeconfig.json

–bundle-output File name where to store the resulting bundle, ex. /tmp/groups.bundle [required]

–sourcemap-output File name where to store the sourcemap file for resulting bundle, ex. /tmp/groups.map

–assets-dest Directory name where to store assets referenced in the bundle

–verbose Enables logging [default: false]

打包步驟

1.在工程根目錄下執行打包命令,比如 
react-native bundle --entry-file index.android.js --bundle-output ./android/app/src/main/assets/index.android.jsbundle --platform android --assets-dest ./android/app/src/main/res/ --dev false
注意:[./android/app/src/main/assets/]資料夾存在

2.增量升級的話不要把圖片資源直接打包到res中,指令碼如下: 
react-native bundle --entry-file index.android.js --bundle-output ./bundle/androidBundle/index.android.jsbundle --platform android --assets-dest ./bundle/androidBundle/ --dev false

3.保證MainActivity.Java中的setBundleAssetName與你的jsbundle檔名一致,比如.setBundleAssetName(“index.android.jsbundle”)就與我生成的資源名一致

IOS

打包命令:

Options:

–entry-file Path to the root JS file, either absolute or relative to JS root [required]

–platform Either “ios” or “android”

–transformer Specify a custom transformer to be used (absolute path) [default: “/Users/babytree-mbp13/projects/xcodeProjects/AwesomeProject/node_modules/react-native/packager/transformer.js”]

–dev If false, warnings are disabled and the bundle is minified [default: true]

–prepack If true, the output bundle will use the Prepack format. [default: false]

–bridge-config File name of a a JSON export of __fbBatchedBridgeConfig. Used by Prepack. Ex. ./bridgeconfig.json

–bundle-output File name where to store the resulting bundle, ex. /tmp/groups.bundle [required]

–sourcemap-output File name where to store the sourcemap file for resulting bundle, ex. /tmp/groups.map

–assets-dest Directory name where to store assets referenced in the bundle

–verbose Enables logging [default: false]

打包步驟

1.在工程根目錄下執行打包命令,比如react-native bundle –entry-file index.ios.js –bundle-output ./bundle/iosBundle/index.ios.jsbundle –platform ios –assets-dest ./bundle/iosBundle –dev false 
注意要先保證bundle資料夾存在。 
2.在xcode中新增assets【必須用Create folder references的方式,新增完是藍色資料夾圖示】和index.ios.jsbundle 
3.參考官方文件,修改AppDelegate.m檔案,使用OPTION 2處的程式碼 jsCodeLocation = [[NSBundle mainBundle] URLForResource:@”index.ios” withExtension:@”jsbundle”];

ios打包遇到的問題

1.離線包如果開啟了chrome除錯,會訪問除錯伺服器,而且會一直loading出不來。 
2.如果bundle的名字是main.jsbundle,app會一直讀取舊的,改名就好了。。。非常奇葩的問題,我重新刪了app,clean工程都沒用,就是不能用main.jsbundle這個名字。 
3.必須用Create folder references【藍色資料夾圖示】的方式引入圖片的assets,否則引用不到圖片 
4.執行bundle命令之前,要保證相關的資料夾都存在

相關推薦

react-native離線bundle

Android 打包命令: eact-native bundle Options: –entry-file Path to the root JS file, either absolute or relative to JS root [required] –

React Native 離線注意事項

react-native bundle Options(可選引數說明): --entry-file :JS根目錄檔案(Path to the root JS file, either absolut

react native app離線打包準備

Android 新增main.jsbundle檔案 新增寫檔案程式碼 private static final String JSBUNDLE_FILE = "main.jsbundle"; private static void copyFi

React Native工程離線執行(ios)

React Native工程離線執行的重點是將index.ios.bundle檔案儲存在機器本地,index.ios.bundle檔案是工程編譯後的js檔案的打包,index.ios.bundle 將被 packager伺服器 建立。。 純RN工程 純RN工

React native的正確姿勢——基於metro bundle

1、分包   觀察現在一些接入React native的大廠,如菜鳥、大搜車、去哪兒,都將react native 的jsbundle分為幾個包來使用。作用是啥?為什麼要這麼折騰?像去哪兒、騰訊或者攜程都發布了一些文章來闡述分包的原因了,不瞭解的可以去搜索看看。我這邊只總結

React Native bundle 打包、拆工具之moles-packer

oles-packer 是由攜程框架團隊研發的,與攜程moles框架配套使用的React Native 打包和拆包工具,同時支援原生的 React Native 專案。 安裝 從npm倉庫中安裝 npm install -g moles-packer 獲取幫助資訊 m

[React-Native] Unable to load script from assets 'index.android.bundle'.

unable als android win oid .com -i ets ava react native for android 拋出下面異常,解決方法: java.lang.RuntimeException: Unable to load script from

Android StudioReact Native創建的項目

inf mage eight 分享 post 分享圖片 技術 blog width 1、點擊 Import project 2、找到項目下android文件夾,選擇build.gradle文件,open Android Studio打開React Nat

react-native修改android

oid dap 導致 activity androi ack adl ... objective 安卓以包名作為應用的唯一id。 假設包名為com.oc.objective,以下地方需要修改。 兩個java文件 android/app/src/main/java/com/

Android原生專案引入最新的React Native

做一個記錄,解決androidstudio無法下載最新的React Native問題 在你的 android/app/build.gradle新增程式碼 compile 'com.facebook.react:react-native:<your_version_h

react-native 500 Unable to resolve module 'AccessibilityInfo', when trying to create release bundle.

react-native 在pc端使用模擬器時遇到的RN版本衝突問題的解決方案: 配置react-native環境中,編譯執行React Native 應用時,出現紅屏,500錯誤。錯誤:“Unable to resolve module 'AccessibilityInf

react-native 啟動的時候報錯unable to load script from assets 'index.android bundle'

實行命令react-native run-android報以下錯誤 unable to load script from assets 'index.android bundle'  ,make sure your bundle is packaged correctly or y

react-native-android-unity(二)建立unity專案,並匯出為android程式碼,嵌入android專案中

1.建立unity專案 給Main Camera新增指令碼Android,使用C#開發,指令碼內容如下: using System.Collections;
using System.Colle

修改 React-Native Android App

轉載自:http://www.th7.cn/Program/Android/201609/965448.shtml ReactNative 不知道是為什麼(大概是依賴太多?),每次執行 react-native init 建立新專案的時候,總是要等個將近 10 分鐘的樣子

React Native專案修改

打release包時,要修改包名 1,修改defaultConfig, applicationId:應用的唯一標識() versionCode :釋出到平臺後,版本更新使用(版本迭代時注意) versionName:顯示應用的版本(作用不大)   2,修改MainActi

React Native入門篇—第三步專案常用依賴的安裝和配置

本人學習React Native沒有看過任何教學視訊,都是按照官網一步步學習的。只研究了Android開發,所以下面的教程都是Android開發教程。 注意:未經允許不可私自轉載,違者必究 React Native官方文件:https://reactnative.cn/docs

react-native修改android名-上傳應用市場

➢ 安卓以包名作為應用的唯一id 假設包名為com.hourglasstime,需要修改以下幾個地方。 ➢ 兩個java檔案 1.androidApp\android\app\src\main\java\com\hourglasstime\MainActivity.java

React-native 完美解決 Unable to load script from assets “index.android.bundle” 和 JS server not recognize

前言: React-Native的第一個HelloWorld工程,大多數人都能跑起來,可也有一部分人卡在第一個工程,就是難以跑出正確的介面,乾著急… 我這裡給出我遇到的坑,希望能夠幫助你,首先,給出我現在的開發環境版本: 版本宣告: Node.js : v8.9.4 Re

React native修改

作為剛入手React native的我,一般是跟著文件走下來的,那麼包名就隨著我初始專案時的名稱了,比如 react-native init myProject ,包名預設為 com.myProject。那麼問題來了,專案後期好多介面是依賴於包名的,比如微信分享

win10 windows10 react-native rn 環境安裝配置Unable to load script from assets 'index.android.bundle終極解決方案

首先說明一下我的情況,新手開始學rn,之前只看過阮一峰大神和一個翻譯國外react入門的文章,然後直接開始rn配置,也是一步一步看著網上的教程開始的,剛開始問題太多,沒有寫中間的bug,直到最後這一個bug搞了我半個下午半個上午,今天上午終於看到期望已久的hello wor