IjzerenHein / react-native-bundle-visualizer

See what packages are increasing your react-native bundle size 📦
MIT License
1.47k stars 44 forks source link

Nx compatible? #93

Closed flexbox closed 1 year ago

flexbox commented 2 years ago

Hey Thank you for this cool library!

I had a look at #74 and I think I am running in —more or less— the same issue.

My stack is a React Native Library, created with Nx Here is an example https://github.com/flexbox/react-native-nx-monorepo

Does anyone know how to make it run with NX? ?

MikeSpitz commented 1 year ago

@flexbox Did you get anywhere with figuring out how to fix this or measure bundle size for react native apps on NX in the end? Currently hitting same issue as you are

flexbox commented 1 year ago

Hey @MikeSpitz Unfortunately no, I tried for a day a gave up on this.

I will close for now because it seems out of scope and monorepo with Nx is a very different world Vs "classic" apps.

keithchan-bowtie commented 1 year ago

@flexbox @MikeSpitz

I have a trick to support Nx.

Firstly, configure your project.json to output the sourcemap as follow. https://nx.dev/packages/react-native/executors/bundle#examples

Then you can see both main.jsbundle and main.map inside dist/apps/<your_app>/ios or dist/apps/<your_app>/android

Update the last line in main.jsbundle to main.map instead of the relative path

image

to

image

Then install https://github.com/danvk/source-map-explorer

Then run yarn source-map-explorer dist/apps/<app>/<platform>/main.jsbundle

Since source-map-explorer cannot specify the sourcemap path, so I have to manually update it in main.jsbundle If I won't do this, source-map-explorer will resolve the path into like ...dist/apps/dist/apps..., duplicating the dist/apps, I suspect it is due to the ../../ relative path set during executing @nrwl/react-native:bundle. But we have to do that to put the main.map besides main.jsbundle.

Let me know if you guys got tricks to skip the manual part.

keithchan-bowtie commented 1 year ago

https://github.com/nrwl/nx/blob/master/packages/react-native/src/executors/bundle/schema.json there is the sourcemapSourcesRoot to configure... not yet got time to try out. @flexbox

flexbox commented 1 year ago

Thank you for the feedback @keithchan-bowtie Maybe we can try to "half-automate" the process with patch-package. If I land on a solution I will post an update here 😀