Skip to content

Use PostCSS through Node for Sass compilation#6151

Merged
aduth merged 4 commits intomainfrom
aduth-build-sass-postcss
Apr 5, 2022
Merged

Use PostCSS through Node for Sass compilation#6151
aduth merged 4 commits intomainfrom
aduth-build-sass-postcss

Conversation

@aduth
Copy link
Contributor

@aduth aduth commented Apr 4, 2022

Why:

  • To consolidate fragmented build apparatus
  • To improve build performance†, where Ruby-based autoprefixer-rails is doing the same work, but by a process spawned through Ruby via ExecJS
    • † This benefit is likely limited to development. Since this does add a new PostCSS plugin where one did not exist previously (CSSNano), there could be a net-increase in build time for production-optimized builds.
  • To have more control over dependency tree to use the latest version
    • Current latest autoprefixer-rails uses outdated autoprefixer@10.4.2, where current latest Autoprefixer is autoprefixer@10.4.4
  • Allows us to (re-?)integrate CSSNano plugin for optimized output

While we already have basic CSS minification through Sass's "compressed" style output, CSSNano includes quite a few more optimizations that transform the output, while Sass's compressed output is largely concerned with omitting additional whitespace.

Performance:

RAILS_ENV=production rake assets:precompile && \
  du -sh public/assets/application-[hash].css && \
  gzip-size public/assets/application-[hash].css && \
  brotli-size public/assets/application-[hash].css
Compression Before After Diff Diff%
Raw 392kb 348kb -44kb -11.2%
Gzip 53.9kb 48kb -5.9kb -10.9%
Brotli 40.3kb 36.7kb -3.6kb -8.9%

aduth added 3 commits April 4, 2022 16:20
**Why**:

- To consolidate fragmented build apparatus
- It's probably faster than Ruby, which is doing the same work, but by a process spawned through Ruby via ExecJS
- Allows us to (re-)integrate CSSNano plugin for optimized output
Changelog, Improvements, Optimization, Reduce size of CSS stylesheets
Copy link
Contributor

@mitchellhenke mitchellhenke left a comment

Choose a reason for hiding this comment

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

👏🏼 👏🏼 👏🏼

changelog: Improvements, Optimization, Reduce size of CSS stylesheets
@aduth aduth merged commit 476597b into main Apr 5, 2022
@aduth aduth deleted the aduth-build-sass-postcss branch April 5, 2022 14:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants