XRPL Styles
This folder contains the source files for the XRP Ledger Dev Portal CSS. The optimized, minified version of these styles is /static/css/devportal2024-v1.css.
Build Pipeline
The CSS build uses a modern optimization pipeline:
- Sass - Compiles SCSS to CSS
- PostCSS - Processes CSS with plugins:
- PurgeCSS - Removes unused CSS (production only)
- Autoprefixer - Adds vendor prefixes for browser compatibility
- cssnano - Minifies and optimizes CSS (production only)
Performance Improvements
The optimized build dramatically improves CSS delivery:
| Metric | Before | After | Improvement |
|---|---|---|---|
| Uncompressed | 486.64 KB | 280.92 KB | 42% smaller |
| Gzipped (network) | 71.14 KB | 43.32 KB | 39% smaller |
This improves page load times, developer experience (DevTools filter: 60s → <1s), and reduces bandwidth costs.
Prerequisites
All dependencies are automatically installed via NPM:
npm install
Key dependencies:
sass- SCSS compilerpostcss-cli- PostCSS command-line interface@fullhuman/postcss-purgecss- Removes unused CSSautoprefixer- Browser compatibilitycssnano- CSS minification
Building
Production Build
For production deployments with full optimization:
npm run build-css
Includes: PurgeCSS, autoprefixer, minification (no source maps)
Development Build
For local development with debugging:
npm run build-css:dev
Includes: Autoprefixer, source maps (no PurgeCSS for faster builds)
Watch Mode
For continuous compilation during development:
npm run build-css:watch
Auto-rebuilds on file changes with source maps
Analysis
To analyze the CSS bundle composition:
npm run analyze-css
This shows:
- Bundle size and selector counts
- Bootstrap component usage
- Custom component patterns
- Optimization recommendations
Files Structure
Main Entry Point
xrpl.scss- Master file that imports all other SCSS files, Bootstrap, and defines variables
Component Styles
Each _*.scss file contains styles for specific components:
_colors.scss- Color palette and variables_font-face.scss- Font definitions_font.scss- Typography styles_layout.scss- Page layout and grid_buttons.scss- Button styles_forms.scss- Form controls_cards.scss- Card components_nav-*.scss- Navigation components (top-nav, side-nav)_content.scss- Content area styles_blog.scss- Blog-specific styles_dev-tools.scss- Developer tools styles_rpc-tool.scss- RPC tool interface_tables.scss- Table styles_footer.scss- Footer styles_callouts.scss- Callout/alert boxes_diagrams.scss- Diagram styles_print.scss- Print media styleslight/_light-theme.scss- Light theme overrides
Configuration
PostCSS Configuration
The PostCSS pipeline is configured in postcss.config.cjs at the project root.
PurgeCSS Safelist:
- Scans all
.tsx,.md,.yaml, and.htmlfiles for class names - Preserves dynamically-added classes (Bootstrap JS components, CodeMirror, etc.)
- Keeps state classes (
active,disabled,show, etc.) - Only runs in production builds
Sass Configuration
Sass is configured via command-line flags in package.json:
--load-path styles/scss- Additional import paths--source-map- Generate source maps (dev only)
Troubleshooting
"Classes are missing after build"
If you find missing styles after a production build:
- Check if the class is dynamically added via JavaScript
- Add the class pattern to the safelist in
postcss.config.cjs - Rebuild:
npm run build-css
Example safelist patterns:
deep: [
/my-dynamic-class/, // Keeps .my-dynamic-class and children
]
"Build is too slow"
For development, use:
npm run build-css:watch # Watch mode (no PurgeCSS)
# or
npm run build-css:dev # One-time dev build (no PurgeCSS)
"Seeing Sass deprecation warnings"
The warnings about @import are from Bootstrap 5's use of legacy Sass syntax. They're harmless and will be resolved when Bootstrap updates to the new @use syntax.
Adding New Styles
When adding new component styles:
- Create
_component-name.scssin this directory - Add
@import "_component-name.scss";toxrpl.scss - If using dynamic classes, add them to the PurgeCSS safelist in
postcss.config.cjs - Test:
npm run build-css:dev(dev) andnpm run build-css(prod) - Analyze:
npm run analyze-css
Further Reading
See CSS-OPTIMIZATION.md in the project root for detailed information about the optimization implementation and migration process.