Skip to content

Build System and Tooling

OpenLayers uses a comprehensive build system based on npm scripts and modern JavaScript tooling to transform TypeScript source code into distributable packages. This system handles transpilation, bundling, type generation, testing, and development workflow automation.

Build Pipeline Architecture

The build pipeline transforms source files through multiple stages using npm scripts defined in package.json. The pipeline handles TypeScript compilation, module bundling, and package preparation.

Build Pipeline Flow

SVG
100%

Core Build Scripts

The build system uses npm scripts that orchestrate file operations, transpilation, and bundling:

ScriptCommandPurpose
transpileshx rm -rf build/ol && shx mkdir -p build/ol && shx cp -rf src/ol build && node tasks/serialize-workers.cjs && node tasks/set-version.jsPrepares source files, processes workers, sets version
build-indexshx rm -f build/index.js && npm run transpile && node tasks/generate-index.jsCreates main module entry point
build-fullshx rm -rf build/full && npm run build-index && npx rollup --config config/rollup-full-build.jsBundles library using Rollup
copy-cssshx cp src/ol/ol.css build/ol/ol.cssCopies CSS stylesheet
generate-typestsc --project config/tsconfig-build.json --declaration --declarationMap --emitDeclarationOnly --outdir build/olGenerates TypeScript declarations
build-packagenpm run build-full && npm run copy-css && npm run generate-types && node tasks/prepare-package.jsAssembles final distribution package

Build Process Steps

1. Transpilation (transpile)

This initial step prepares the source files for further processing:

  • Cleans the build/ol directory
  • Creates necessary directories
  • Copies source files from src/ol to build
  • Processes web worker files via serialize-workers.cjs
  • Sets version information via set-version.js

2. Index Generation (build-index)

This step creates the main entry point:

  • Removes any existing build/index.js
  • Ensures transpilation is complete
  • Generates an index file from the transpiled source using generate-index.js

3. Full Build (build-full)

This step creates a bundled version of the library:

  • Cleans the build/full directory
  • Ensures the index is generated
  • Uses Rollup to create a bundled version with all dependencies

4. Type Generation (generate-types)

This step creates TypeScript declaration files:

  • Uses TypeScript compiler with a specific configuration
  • Generates .d.ts and .d.ts.map files
  • Outputs to build/ol directory

5. Package Creation (build-package)

This final step creates the complete distribution package:

  • Ensures the full build is complete
  • Copies CSS files to the build directory
  • Ensures type declarations are generated
  • Prepares the final package for distribution via prepare-package.js

Dependency Management

OpenLayers maintains a minimal runtime footprint with only five production dependencies while using an extensive development toolchain for building, testing, and development.

Runtime Dependencies

SVG
100%

Development Toolchain Dependencies

CategoryKey DependenciesPurpose
Build Toolsrollup@^4.1.4, typescript@5.8.3, webpack@^5.27.2Module bundling and compilation
Testingkarma@^6.3.8, mocha@11.7.1, puppeteer@24.16.1Browser and Node.js testing
Code Qualityeslint@^9.16.0, eslint-config-openlayers@^20.0.0Linting and style enforcement
Documentationjsdoc@4.0.4, metalsmith@^2.5.0, marked@16.1.2API docs and examples
Developmentwebpack-dev-server@^5.0.2, express@^5.1.0Development server

Testing Infrastructure

OpenLayers implements a multi-layered testing strategy covering code quality, type safety, unit tests, integration tests, and visual regression testing.

Testing Pipeline

SVG
100%

Karma Browser Testing Configuration

The browser test environment uses Karma with sophisticated webpack integration:

SVG
100%

Test Categories

Test TypeRunnerConfigurationPurpose
LintingESLinteslint-config-openlayersCode style and quality
Type CheckingTypeScripttsconfig.json, config/tsconfig-strict.jsonType safety
Unit TestsKarma + Mochatest/browser/karma.config.cjsBrowser compatibility
Node TestsMochatest/node/Server-side functionality
Visual TestsCustomtest/rendering/Rendering accuracy

Development Workflow

OpenLayers provides dedicated npm scripts for different development scenarios, from core library development to examples and documentation.

Development Server Setup

SVG
100%

Core Development Workflows

WorkflowCommandsPurpose
Library Developmentnpm run transpile → npm test → npm run build-packageCore library changes
Example Developmentnpm start → edit → refresh browserInteractive examples
API Documentationnpm run apidocGenerate documentation
Full Release Buildnpm run build-packageDistribution preparation

Example Development Process

The examples system provides immediate feedback for development:

  1. Start Development Server: npm start launches webpack-dev-server with hot reloading
  2. Live Development: Changes to example code automatically refresh the browser
  3. Production Build: npm run build-examples creates optimized examples in build/examples/

Build Outputs

The build process creates these outputs:

OutputLocationDescription
Transpiled Sourcebuild/ol/Processed source files
Index Filebuild/index.jsMain entry point
Full Buildbuild/full/Bundled library
TypeScript Declarationsbuild/ol/*.d.tsType definitions
CSSbuild/ol/ol.cssStylesheet
Packagebuild/Complete distribution package

API Documentation Generation

OpenLayers also includes scripts for generating API documentation:

ScriptPurpose
apidocGenerates API documentation using JSDoc
apidoc-debugGenerates API documentation with debugging enabled

These scripts use JSDoc with a custom configuration to generate documentation from the source code comments.

Examples Building

The example system has dedicated build scripts:

ScriptPurpose
serve-examplesStarts a webpack dev server for examples
build-examplesBuilds examples for production

The examples use webpack for bundling and development serving.