Skip to content

Support modular / lazy loading of Mapbox GL JS to avoid monolithic bundles #132

@agracia-foticos

Description

@agracia-foticos

At the moment, mapbox-gl seems to be bundled as a single, monolithic chunk when using nuxt-mapbox. This makes the initial client bundle quite heavy, even in cases where:

the map is only used on specific routes

advanced features (terrain, 3D buildings, indoor, etc.) are not needed

the map could be loaded lazily after initial render

I was wondering if it would be possible for nuxt-mapbox to support a more modular or chunked loading strategy, for example:

Lazy-loading mapbox-gl only when a component is mounted

Exposing an option to load mapbox-gl via dynamic import instead of static import

Allowing optional features (terrain, indoor, 3D, wasm helpers) to be loaded on demand

Providing guidance or configuration for better code-splitting with Vite (e.g. manualChunks)

I understand that Mapbox GL JS itself is largely monolithic, but even moving it out of the main app chunk and into a route-level or async chunk would significantly improve first-load performance in Nuxt apps.

Example use case

Nuxt app with multiple routes

Only one route contains a map

Currently, mapbox-gl is included in the main client bundle

Desired behavior: mapbox code is downloaded only when the map route is visited

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions