Skip to content

Conversation

@metonym
Copy link
Contributor

@metonym metonym commented Sep 13, 2025

Review by commit.

Note: Git diff is massive since the lockfile has not been checked in to source control. Rebase on #235

This is optional, but I recommend incorporating the Carbon preprocessor for faster development/production builds and optimized CSS generation.

Svelte has first-class support for preprocessors. This means that code can be transformed before compilation.

carbon-preprocess-svelte automatically processes source code to rewrite Carbon imports to their optimized path, greatly reducing the number of initially loaded components.

# Carbon preprocessor automatically optimizes imports to avoid the barrel import penalty.
- import { Button } from "carbon-components-svelte";
+ import Button from "carbon-icons-svelte/src/Button/Button.svelte";

In the case of Carbon, I recommend the following:

  • optimizeImports: automatically rewrites Carbon imports to the optimized path. Carbon has a lot of exports from its barrel file. Optimizing imports can greatly reduce cold start and build times, since it bypasses the barrel file.
  • optimizeCss: Vite plugin that optimizes CSS from carbon-components-svelte at build time.

Results

Running locally on my machine, I observe ~1.21x (~17%) faster build times and ~45.8% reduced CSS output size (non-gzip).

npm run build

- ✓ 2204 modules transformed.
- ✓ built in 4.69s

+ ✓ 1970 modules transformed.
+ ✓ built in 3.86s

Optimized CSS

- .svelte-kit/output/client/_app/immutable/assets/0.BtlGoQkA.css    606.87 kB │ gzip:  55.92 kB
+ .svelte-kit/output/client/_app/immutable/assets/0.BtlGoQkA.css    328.90 kB │ gzip:  31.25 kB

Luke-Roy-IBM
Luke-Roy-IBM previously approved these changes Sep 23, 2025
Copy link
Member

@Luke-Roy-IBM Luke-Roy-IBM left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Copy link
Member

@Luke-Roy-IBM Luke-Roy-IBM left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Luke-Roy-IBM Luke-Roy-IBM merged commit 96fd947 into IBM:main Sep 24, 2025
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants