Expo-CLI的Metro工具生成的编译后JavaScript文件存放在什么位置?
Expo 安卓平台Metro打包产物存储路径
开发调试模式
开发模式下Metro默认采用内存打包机制,不会主动将完整bundle持久化写入磁盘,如需导出完整JS文件排查问题,需手动执行导出命令:npx expo export --dev --dump-sourcemap
- 执行命令后,产物默认输出到项目根目录的
dist文件夹下,安卓端主JS bundle路径为:dist/_expo/static/js/android/index-<随机哈希>.js,同名sourcemap文件也存储在同目录。 - 如需开启开发模式持久化缓存,可在
metro.config.js中添加如下配置,缓存的中间产物将存储在项目根目录.metro/cache路径:
const { getDefaultConfig } = require('expo/metro-config'); const config = getDefaultConfig(__dirname); config.cacheStores = ({ FileStore }) => [ new FileStore({ root: './.metro/cache', }), ]; module.exports = config;
生产构建模式
- 执行本地生产构建
expo run:android --variant release时,生成的JS bundle默认存储路径为:android/app/build/generated/assets/createBundleReleaseJsAndAssets/index.android.bundle - 也可手动指定产物输出路径执行打包:
npx react-native bundle --platform android --dev false --entry-file index.js --bundle-output ./android-release.bundle --sourcemap-output ./android-release.bundle.map
依赖语法问题排查提示
拿到bundle和sourcemap文件后,可直接使用
source-map-explorer工具定位报错代码对应的原始模块,无需手动遍历bundle内容,执行命令为:npx source-map-explorer <bundle文件路径> <sourcemap文件路径>
内容的提问来源于stack exchange,提问作者Archimedes Trajano
相关产品推荐
相关产品推荐

