Which CSS strategy best minimizes unused styles when importing Bulma without Sass?
0 reputation · 05 Nov 2022, 23:16 UTC
0 reputation · 05 Nov 2022, 23:16 UTC
Bulma provides a comprehensive set of CSS classes for its 12-column Flexbox grid and various UI components. While using the Sass source allows for selective importing of specific modules, many projects rely on the pre-compiled CSS file for simplicity.
Including the full compiled CSS file introduces a significant amount of unused styling into the production environment, as the browser must parse the entire framework regardless of which modifiers or components are actually utilized in the HTML.
Given that Bulma is a strictly CSS-based framework without a JavaScript runtime to handle dynamic loading, what are the most effective methods for reducing this CSS bloat? Does the framework support a lightweight distribution, or is a third-party purging tool the only viable option for optimizing the final bundle size?
With pre-compiled Bulma CSS and no Sass build step, the only production-ready way to remove unused styles is content-based purging of the static CSS file in your build pipeline. PurgeCSS or UnCSS scanning your HTML/JS templates and stripping selectors not found is the effective strategy. Bulma does not ship an official lightweight distribution or modular CDN splits for the compiled CSS.
Selective importing requires the Sass source. When you are locked to the compiled file, runtime techniques are not available because Bulma is CSS-only. Post-build purging is therefore the runtime-agnostic approach: a build tool scans your source files for class names, keeps matches, and drops the rest. Manual custom builds via Sass would be smaller, but that adds a Sass step which you said is not in use.
/^is-/, /^has-/.One diagnostic detail that changes the recommendation: are Bulma classes added dynamically at runtime via JavaScript, template literals or a classnames utility? If yes, you need custom extractors and a broader safelist, otherwise static scanning will remove classes that are only composed in code.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.