Open samanpwbb opened 3 years ago
It looks like we could fix this by updating the exclude regex in getConfigForNodeModules:
Do we know if doing this works for both gl-js v1 and v2?
Do we know if doing this works for both gl-js v1 and v2?
I'm not sure but this should be pretty easy to test.
@samanpwbb I think you approach of adding gl-js v2 to exclude: /@babel(?:\/|\\{1,2})runtime/,
should work. My only suggestion would be to make sure that it is only added if the consumer actually has gl-js v2, so that we dont end up breaking anything for folks using underreact v1. I guess we can do this check by checking the version of gl-js and only then adding the exclusion.
Why not just add an new option as excludeNodeModules
than a hack towards mapbox-gl? As mapbox-gl-js V2.0.1 support external worker, how underrect handle this if we want transpile mapbox-gl-js V2?
If we add special processing towards mapbox-gl, does it mean we should add support for mapbox-gl-style-spec、p-finally and more. I think underreact is a generic webpack based build tool that should not give mapbox-gl a special hack.
Why not just add an new option as
excludeNodeModules
than a hack towards mapbox-gl? As mapbox-gl-js V2.0.1 support external worker, how underrect handle this if we want transpile mapbox-gl-js V2?
I think I agree - am going to add a second PR that does this, and defaults to including gl js in the exclude list
Out of the box, underreact does not support the latest version of
mapbox-gl
. Since underreact is often used by apps that use Mapbox, the two projects should be compatible. Read more about whymapbox-gl
breaks here: https://github.com/mapbox/mapbox-gl-js/issues/10173The basic problem is related to transpiling gl js's worker code:
There are two possible fixes, documented here:
I suggest option 1: It saves us bundle size and may also speed up time to first render (it's 31% lighter, saving 68kb). GL JS 2.0 does not support IE11 at all anymore, so transpiling for IE11 isn't serving any purpose. Option 1 is also what GL JS team recommends.
It looks like we could fix this by updating the exclude regex in
getConfigForNodeModules
: https://github.com/mapbox/underreact/blob/dcb5edc64d407304c93612c62ad73890ad37a49e/lib/webpack-config/babel-loader-config.js#L81We could also consider supporting both options, but defaulting to 1.
@kepta would love your input. This issue has a little bit of urgency, as many frontend apps at Mapbox are going to be switching to 2.0 soon.