Skip to content

Build System

Overview

The build uses Rollup (v2) to produce 4 independent IIFE bundles. Each bundle has 3 variants:

Variant Filename Command
Development dist/*-dev.js bun run build-dev
Production (unminified) dist/*-unminified.js bun run build-prod
Production (minified) dist/*.js bun run build-prod-min

Bundle Configuration

Entry Point Output Content
src/index.js dist/map.js Maps + Indoor (main bundle)
src/widgets-library.js dist/widgets.js UI widgets (navigation, indoor panel)
src/drawing/index.js dist/drawing.js Drawing tools
src/index_services.js dist/services.js API services only (no map rendering)

Two-Pass Map Bundle

The main map.js bundle uses a unique two-pass Rollup strategy to handle the Mapbox GL web worker:

Pass 1 — Code Splitting

  • Input: src/index.js + mapbox-gl/src/source/worker.js
  • Output: AMD chunks in rollup/build/map/
  • Splits into: main chunk, worker chunk, shared chunk
  • Plugins: Flow removal, Buble transpilation, GLSL inlining, PostCSS
  • Tree shaking: enabled

Pass 2 — Assembly

  • Input: rollup/map.js (references the AMD chunks)
  • Output: Single IIFE in dist/map[-dev|-unminified].js
  • Intro: Custom AMD loader from rollup/bundle_prelude.js
  • Tree shaking: disabled (chunks are pre-optimized)
  • Sourcemaps: ingested from pass 1

The custom AMD loader in bundle_prelude.js allows the worker to be embedded inline rather than loaded as a separate file.

Other Bundles

Widgets, Drawing, and Services bundles use a single-pass Rollup build:

  • Format: IIFE
  • Tree shaking: disabled
  • Sourcemaps: enabled
  • Plugins: same transform chain as pass 1

Rollup Plugins

Shared plugins defined in build/rollup_plugins.js:

Plugin Purpose
@rollup/plugin-strip Remove console.log and assert in production
rollup-plugin-flow Strip Flow type annotations
@nicolo-ribaudo/rollup-plugin-buble Transpile ES2015+ to ES5 (no Babel needed)
@nicolo-ribaudo/chokidar-2 File watching
rollup-plugin-glslify Inline GLSL shader files
rollup-plugin-postcss Process CSS with PostCSS
@nicolo-ribaudo/rollup-plugin-terser Minification (production builds)
rollup-plugin-json Import JSON files
@nicolo-ribaudo/rollup-plugin-node-resolve Resolve node_modules
@nicolo-ribaudo/rollup-plugin-commonjs Convert CommonJS to ES modules
@nicolo-ribaudo/rollup-plugin-replace Inject environment variables

CSS Build

PostCSS compiles src/css/map.css to dist/map.css:

bun run build-css

PostCSS plugins:

  • postcss-inline-svg — inline SVG files
  • cssnano — CSS minification

The CSS uses mapboxgl-* class namespace inherited from Mapbox GL.

Icon Sprites

bun run build-icons

Generates sprite sheets from PNG source images via build/sprite_from_png.js.

Build Configuration Files

File Purpose
rollup.config.js Main 4-config Rollup setup
rollup.config.csp.js CSP-compatible build variant
build/rollup_plugins.js Shared plugin definitions
rollup/bundle_prelude.js Custom AMD loader for worker embedding
rollup/map.js Pass 2 entry for map bundle assembly
babel.config.cjs Babel with Flow preset (for Webpack/tests)
postcss.config.js PostCSS with inline-svg and cssnano
environment.js Per-environment URL definitions

Environment Switching

The environment.js file defines URLs per environment, injected at build time:

// WOOSMAP_ENV=prod
{
    API_BASE_URL: "https://api.woosmap.com",
    ASSETS_BASE_URL: "https://sdk.woosmap.com/map",
    MAPS_BUNDLE_NAME: "map.js",           // minified
    WIDGETS_BUNDLE_NAME: "widgets.js",
    DRAWING_BUNDLE_NAME: "drawing.js",
    MAPS_STYLE_NAME: "map.css",
}

Unminified builds use dist/map-unminified.js naming; dev builds use dist/map-dev.js.