React-Native之制作離線bundle

關(guān)于react-native bundle

react-native bundle是react-native-cli的一個命令,制作離線包需要用到react-native bundle命令行,我們先來了解下react-native?bundle可選參數(shù)都有哪些,如果熟悉webpack打包的朋友對下面的參數(shù)會很熟悉:

--entry-file <path>:配置入口JS文件路徑,可以是絕對路徑,也可以是相對于根目錄的相對路徑。

--platform [string]:需要編譯的平臺,“ios”或“android”(默認(rèn):ios)。

--transformer [string]:指定要使用的自定義代碼轉(zhuǎn)換工具。

--dev [boolean]:是否使用開發(fā)者環(huán)境,如果是false,則禁用警告并將壓縮代碼(默認(rèn)為true)。

--minify [boolean]:是否壓縮代碼。如果dev為真,則默認(rèn)為false,如果dev為false,則為true。禁用迷你化可以加速構(gòu)建,對于測試是很有用的。

--bundle-output <path>:bundle的輸出路徑,用于存儲所打包后的代碼。

--bundle-encoding [string]:編碼。(默認(rèn)值:utf8)。

--max-workers [number]:指定用于轉(zhuǎn)換文件的最大工作池。這個默認(rèn)值是電腦可用的內(nèi)核數(shù)。

--sourcemap-output [string]:sourcemap的輸出文件名。

--sourcemap-sources-root [string]:sourcemap的輸出目錄(默認(rèn)要寫相對路徑)。

--sourcemap-use-absolute-path:啟用sourcemap輸出目錄使用絕對路徑。

--assets-dest [string]:bundle中引用的文件目錄名稱。

--verbose:啟用日志。

--reset-cache:刪除緩存文件。

--read-global-cache:從全局緩存中獲取轉(zhuǎn)換的JS代碼。

--config [string]:指定一個CLI配置文件路徑。

-h, --help:使用幫助。


Android打包示例

react-native bundle --entry-file index.android.js --bundle-output ./android/app/src/main/assets/index.android.bundle --platform android --assets-dest ./android/app/src/main/res/ --dev false

注意:1.[./android/app/src/main/assets/]里的assets文件夾若不存在則創(chuàng)建一個。2.增量升級的話不要把圖片資源直接打包到res中,要用--assets-dest ./bundle/androidBundle/?。

IOS打包示例

1.在工程根目錄下執(zhí)行打包命令

react-native bundle –entry-file index.ios.js –bundle-output ./bundle/iosBundle/index.ios.bundle –platform ios –assets-dest ./bundle/iosBundle –dev false?

注意要先保證bundle文件夾存在。?

2.在xcode中添加assets【必須用Create folder references的方式,添加完是藍(lán)色文件夾圖標(biāo)】和index.ios.bundle?

3.參考官方文檔,修改AppDelegate.m文件, jsCodeLocation = [[NSBundle mainBundle] URLForResource:@”index.ios” withExtension:@”bundle”];

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容