Build System
Overview
CivicTheme's build system is a custom asset compilation pipeline designed specifically for Drupal themes. Built around build.js, it provides a simplified, fast approach to managing theme assets while prioritising speed and auditability over complex optimisation features.
The system is engineered to handle the unique requirements of government digital services, ensuring consistent asset delivery across different environments while maintaining the flexibility needed for custom theme development.
Core Architecture
Asset Compilation Pipeline
The build system processes multiple asset types through a unified pipeline:
Combines component directories — uses rsync to merge CivicTheme's components with your sub-theme's components into a temporary
components_combined/directory. This combined directory is used by Storybook so it can render all components together. SDC components ship their own compiled CSS alongside their component files in thecomponents/directory.Compiles SCSS — processes theme-level stylesheets (theme styles, layout styles, editor styles, admin styles, variables) into CSS in
dist/usingsass-embedded. Component-level SCSS is compiled to.cssfiles within each component's own directory.Bundles JavaScript — wraps component JavaScript in Drupal behavior patterns.
Copies assets — moves fonts, icons, images, and other static assets to
dist/assets/.Generates constants — exports SCSS variables, icon names, backgrounds, and logos to
dist/constants.jsonfor use in Storybook.
Component System Integration
The build system manages CivicTheme's component architecture:
Component Combination: Merges base CivicTheme components with custom theme components
SDC Support: Generates isolated CSS/JS for Single Directory Components
Dependency Resolution: Handles imports and ensures proper load order across the component hierarchy
Multi-Environment Output
The system generates optimised outputs for different contexts:
Drupal Integration: Produces files compatible with Drupal's asset management system
Storybook Support: Creates separate builds for the Storybook development environment
Editor/Admin Styles: Generates specialised stylesheets for different Drupal interfaces
Build Modes and Commands
The build system supports multiple operational modes:
Full Build: Complete asset compilation for production deployment
Watch Mode: File system monitoring with automatic rebuilds for development
Selective Building: Targeted compilation of specific asset types (styles, JavaScript, assets)
CLI Integration: Parallel execution of npm scripts for improved performance
Commands
Key output files
dist/styles.base.css
Base component styles
dist/styles.theme.css
Theme-specific styles
dist/styles.variables.css
CSS custom properties (color variables)
dist/scripts.drupal.base.js
JavaScript wrapped in Drupal behaviors
dist/constants.json
SCSS variables, icon names, backgrounds, and logos for Storybook
Configuration and Constants
Theme Detection
The system automatically detects and links to the base CivicTheme installation, ensuring proper inheritance and customisation paths.
Constants Generation
Extracts and processes design tokens including:
Background configurations
Icon definitions
Logo specifications
SCSS variable mappings
Path Management
Handles complex directory structures and relative paths required for Drupal theme integration.
Design Philosophy
The build system makes several deliberate architectural decisions:
Performance Optimisations
Unix-focused: Optimised for Unix-like environments with rsync for efficient file operations
Speed over optimisation: Prioritises build speed over minification/uglification
Selective watching: File monitoring limited to specific file types for efficiency
Minimal dependencies: Uses native Node.js and command-line tools to reduce external dependencies
Critical Assumptions
The system operates under specific technical constraints:
Unix-like environment with rsync availability
CivicTheme directory structure conventions
Drupal integration patterns (behaviours, asset paths)
Component-based architecture with clear separation of concerns
Next Steps
To begin using the build system:
Ensure your environment meets the Unix-like requirements
Review the CivicTheme directory structure conventions
Configure your theme's build settings
Run the initial build process
For detailed implementation guidance, refer to the Drupal theme development documentation.
Last updated
Was this helpful?