Skip to content

Commit 51a6a2c

Browse files
Make mapbox-gl an optional dependency (#2175)
1 parent d24fa18 commit 51a6a2c

File tree

46 files changed

+234
-86
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+234
-86
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import Map from 'react-map-gl';
3131

3232
function App() {
3333
return <Map
34+
mapLib={import('mapbox-gl')}
3435
initialViewState={{
3536
longitude: -100,
3637
latitude: 40,

docs/api-reference/attribution-control.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Map, {AttributionControl} from 'react-map-gl';
88

99
function App() {
1010
return <Map
11+
mapLib={import('mapbox-gl')}
1112
initialViewState={{
1213
longitude: -100,
1314
latitude: 40,

docs/api-reference/fullscreen-control.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Map, {FullscreenControl} from 'react-map-gl';
88

99
function App() {
1010
return <Map
11+
mapLib={import('mapbox-gl')}
1112
initialViewState={{
1213
longitude: -100,
1314
latitude: 40,

docs/api-reference/geolocate-control.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Map, {GeolocateControl} from 'react-map-gl';
88

99
function App() {
1010
return <Map
11+
mapLib={import('mapbox-gl')}
1112
initialViewState={{
1213
longitude: -100,
1314
latitude: 40,

docs/api-reference/layer.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const parkLayer = {
1919

2020
function App() {
2121
return <Map
22+
mapLib={import('mapbox-gl')}
2223
initialViewState={{
2324
longitude: -122.4,
2425
latitude: 37.8,

docs/api-reference/map.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Map from 'react-map-gl';
88

99
function App() {
1010
return <Map
11+
mapLib={import('mapbox-gl')}
1112
initialViewState={{
1213
longitude: -100,
1314
latitude: 40,
@@ -38,7 +39,7 @@ function App() {
3839
});
3940
}, []);
4041

41-
return <Map ref={mapRef} onLoad={onMapLoad} />;
42+
return <Map mapLib={import('mapbox-gl')} ref={mapRef} onLoad={onMapLoad} />;
4243
}
4344
```
4445

@@ -455,7 +456,9 @@ Props in this section are not reactive. They are only used once when the Map ins
455456

456457
#### `mapLib`: any
457458

458-
Override the map library. By default, it loads the mapbox-gl module using [dynamic import](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#dynamic_imports). This can be used to replace mapbox-gl with a compatible fork:
459+
Specify the underlying base map library for the Map component. The value can be provided with several options:
460+
461+
By module import (and embedding in the final bundle):
459462

460463
```js
461464
import * as React from 'react';
@@ -467,6 +470,17 @@ function App() {
467470
}
468471
```
469472

473+
By dynamic import (thus enable bundle splitting):
474+
475+
```js
476+
import * as React from 'react';
477+
import Map from 'react-map-gl';
478+
479+
function App() {
480+
return <Map mapLib={import('mapbox-gl')} />;
481+
}
482+
```
483+
470484
Or to load a pre-bundled version of the library:
471485

472486
```html
@@ -482,7 +496,6 @@ function App() {
482496
}
483497
```
484498

485-
Default: `import('mapbox-gl')`
486499

487500
#### `mapboxAccessToken`: string
488501

docs/api-reference/marker.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Map, {Marker} from 'react-map-gl';
88

99
function App() {
1010
return <Map
11+
mapLib={import('mapbox-gl')}
1112
initialViewState={{
1213
longitude: -100,
1314
latitude: 40,

docs/api-reference/navigation-control.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Map, {NavigationControl} from 'react-map-gl';
88

99
function App() {
1010
return <Map
11+
mapLib={import('mapbox-gl')}
1112
initialViewState={{
1213
longitude: -100,
1314
latitude: 40,

docs/api-reference/popup.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ function App() {
1313
const [showPopup, setShowPopup] = React.useState(true);
1414

1515
return <Map
16+
mapLib={import('mapbox-gl')}
1617
initialViewState={{
1718
longitude: -100,
1819
latitude: 40,

docs/api-reference/scale-control.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Map, {ScaleControl} from 'react-map-gl';
88

99
function App() {
1010
return <Map
11+
mapLib={import('mapbox-gl')}
1112
initialViewState={{
1213
longitude: -100,
1314
latitude: 40,

0 commit comments

Comments
 (0)