Replacing Snowpack as build tool in CoMPAS
This page explains how the current build tool of CoMPAS, Snowpack, is set up and used, and what the options are to replace Snowpack with another build tool.
1. Why replace Snowpack?
Key concerns with continuing to use Snowpack:
No active maintenance since 2021 - Security updates and bug fixes are no longer provided
Package compatibility issues - Modern npm packages may not work correctly
Limited plugin ecosystem - Smaller community support compared to modern alternatives
Migration path needed - Technical debt that will eventually require addressing
2. How is CoMPAS currently being built?
Monorepo structure
compas-open-scd is a monorepo managed by Lerna/Nx with multiple packages. The build architecture uses two different strategies:
Snowpack applications
Two packages use Snowpack to build complete web applications:
packages/compas-open-scd/- Main CoMPAS OpenSCD applicationProduction application for CoMPAS-specific use cases
Build output used to build the
compas-open-scdDocker imageDeployed to demo.compas.energy
packages/distribution/- Official OpenSCD distributionOpenSCD without CoMPAS customizations
Deployed to
openscd.github.ioTo do: decide if this package can be removed from this repository
TypeScript-compiled libraries
Other packages are libraries compiled with TypeScript only (no Snowpack):
@openscd/xml→ Built withtsc(⚠️ Being migrated to external npm package)@openscd/core→ Built withtsc -b(⚠️ Being migrated to external npm package)@openscd/openscd→ Built withtsc(⚠️ Being migrated to external npm package)@openscd/plugins→ Built withtsc(⚠️ Being migrated to external npm package)@openscd/forms→ Built withtsc(⚠️ Minimal/empty, will follow npm package approach)@openscd/addons→ Built withtsc(⚠️ Minimal/empty, will follow npm package approach)@openscd/wizards→ Built withtsc(⚠️ Minimal/empty, will follow npm package approach)
Despite being built with tsc, Snowpack applications do NOT use the library dist/ folders. Instead, Snowpack imports directly from source files (/src/) via mount points and aliases.
Migration status: all library packages (xml, core, openscd, plugins, forms, addons, wizards) are either being or will be transitioned to external npm packages published from a separate repository. Once complete, only compas-open-scd (and potentially distribution?) would need building with a bundler.
3. What needs to be migrated?
Migration scope
When evaluating build tool replacements for Snowpack, the scope is focused on application builds only:
packages/compas-open-scd/- Main production application requiring full build pipeline replacementpackages/distribution/- May not require migration if retired or can use same tooling as main app
Out of scope:
All library packages (
xml,core,openscd,plugins,forms,addons,wizards) - Use simpletsccompilation and all are being/will be migrated to external npm packages
All library packages are transitioning to external npm packages, making the build tool migration a single-application migration focused solely on compas-open-scd. The build tool evaluation can focus on:
Building one TypeScript/web component application (
compas-open-scd)Handling external plugins (git submodules in
external-plugins/)Service worker generation for PWA functionality
Development server with hot module replacement
4. Which build tools can we use, what are the pro's and cons?
Vite
Vite is the unofficial successor to Snowpack. It works pretty similar: native ES modules during dev for fast HMR, then uses Rollup under the hood for production builds.
Pros:
✅ Very similar to what we have now - Same unbundled dev approach as Snowpack
✅ Actually maintained - Unlike Snowpack, this has a large community and receives regular updates
✅ Fast - Cold starts are instant, HMR is comparable to what we're used to with Snowpack
✅ TypeScript support built-in - No extra setup needed, it's included
✅ Rich plugin ecosystem - Significantly more plugins than Snowpack ever had
✅ PWA support covered - There's
vite-plugin-pwathat handles Workbox (we already have this in ourvite.config.ts)✅ Works fine with monorepos - Path aliases and workspace setup is straightforward
✅ Modern defaults - ES2020+, tree-shaking, code splitting all included
Cons:
⚠️ Our plugin loading requires significant changes - This is the main challenge:
We use
import(plugin.src)inopen-scd.ts:475to dynamically load pluginsVite doesn't support fully dynamic imports - it requires glob patterns like
import.meta.glob()or explicit pathsWe'd need to refactor how plugins are loaded - not a small change
Time estimate: approximately 2-3 weeks. Most of this time will be spent on refactoring the plugin loading system.
Webpack
The established standard. Webpack has been the industry-standard bundler for many years. It's highly configurable and has extensive plugin support.
Pros:
✅ Battle-tested - Widely used, with every edge case well-documented
✅ Comprehensive plugin ecosystem - Solutions exist for virtually any build requirement
✅ Fine-grained control - Highly configurable bundling behavior
✅ Strong TypeScript support - Works well with
ts-loaderorbabel-loader✅ Module federation - Advanced features available if needed
✅ Excellent documentation - Comprehensive guides and troubleshooting resources
Cons:
❌ Complex configuration - Configuration files typically require 300-400 lines
❌ Slower dev builds - Full bundling during development, unlike Snowpack's unbundled approach
❌ Slower HMR - While decent (webpack 5 improved this), it's not as fast as Vite/Snowpack
❌ Configuration complexity - Webpack configs can become difficult to maintain
❌ Different mental model - It's all about bundling, very different from Snowpack
❌ More runtime overhead - The bundles include more webpack runtime code
Time estimate: High effort, 3-4 weeks. Significant configuration work, but no code changes required.
esbuild
An extremely fast JavaScript bundler and minifier written in Go. Known for 10-100x faster builds than traditional bundlers.
Pros:
✅ Blazing fast - Written in Go, parallel processing, fastest bundler available
✅ Simple configuration - Minimal config compared to webpack
✅ Built-in TypeScript - No additional plugins needed
✅ Tree-shaking - Dead code elimination built-in
✅ ESM and CJS output - Flexible output formats
✅ Source maps - Built-in support
✅ Watch mode - Fast rebuilds during development
Cons:
❌ No dynamic imports with variable paths - Similar limitation to Vite
CRITICAL ISSUE:
import(\\${variable}\)not supportedWould require plugin system refactoring
❌ Limited plugin ecosystem - Fewer plugins than webpack/Rollup
❌ No HMR support - Must implement manually or use wrapper tools
❌ No built-in dev server - Need external solution
❌ Less mature - Still evolving, some edge cases not handled
❌ Limited CSS handling - Basic CSS bundling only
⚠️ API still stabilizing - Breaking changes possible
Time estimate: Medium-High (2-3 weeks) - Plugin refactoring + infrastructure setup
Rollup
A bundler optimized for libraries with excellent tree-shaking capabilities. Vite uses Rollup internally for production builds.
Pros:
✅ Excellent tree-shaking - Very effective at removing unused code
✅ Clean output - Produces readable bundles with minimal runtime overhead
✅ ESM-first design - Built specifically for modern ES modules
✅ Good plugin selection - Solid collection of official plugins
✅ Flexible output formats - Can generate ESM, CJS, UMD, IIFE
✅ Already in use - Our external plugins use Rollup configs (e.g.,
scl-wizarding/rollup.config.js)✅ Dynamic import plugin available -
@rollup/plugin-dynamic-import-varsmay handle our use case
Cons:
⚠️ Uncertain dynamic import support - The
@rollup/plugin-dynamic-import-varsplugin has limitationsOnly handles glob patterns, not fully dynamic paths
Our
import(\\${correctedSrc}\)pattern may or may not work with proper configurationRequires testing before we can commit to Rollup
❌ No development server - Must set up separately
❌ Slower dev builds - Not as fast as Vite/Snowpack
❌ More configuration needed - Compared to Vite
❌ Library-focused - Applications aren't its primary use case
⚠️ Basic watch mode - Less sophisticated than webpack/Vite
Time estimate: Medium (2-3 weeks) - Configuration + testing dynamic imports
Overview
Criteria | Vite | Webpack | esbuild | Rollup |
|---|---|---|---|---|
Dynamic imports supported | ❌ No | ✅ Yes | ❌ No | ⚠️ Maybe |
Code refactoring required | ✅ Yes | ❌ No | ✅ Yes | ⚠️ Maybe |
Dev server experience | ⭐⭐⭐⭐⭐ | ⭐⭐⭐ | ⭐ | ⭐⭐ |
Build speed | ⭐⭐⭐⭐⭐ | ⭐⭐⭐ | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐ |
Configuration complexity | Low | High | Low | Medium |
Plugin ecosystem | Large | Extensive | Limited | Good |
HMR quality | Excellent | Good | None | None |
Migration effort | Medium | High | Medium | Medium |
Maintenance burden | Low | Medium | Low | Low |
Community support | Large | Very large | Growing | Medium |
TypeScript support | Built-in | Via loader | Built-in | Via plugin |
PWA/Service Worker | Plugin | Plugin | Manual | Manual |
Similarity to Snowpack | High | Low | Medium | Medium |
Production optimisation | Excellent | Excellent | Excellent | Excellent |
Recommendation: Vite
Best long-term choice with modern architecture and excellent developer experience
Requires 2-3 weeks of work including plugin system refactoring
Most similar to Snowpack's development experience