Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify postcss-colormin #1207

Merged
merged 4 commits into from Oct 19, 2021

Conversation

omgovich
Copy link
Contributor

@omgovich omgovich commented Oct 18, 2021

Hey guys!

cssnano already uses colord for color conversions in postcss-colormin and few other packages, but we added 100+ lines around the library to perform the color modification.

Recently I releases colord v2.9 which has built-in color modification utilities so I decided to bring them here and make the cssnano codebase simpler.

The new minifier I implemented inside of colord is also way smarter and performs better compression results.

Example:

SOURCE
rgba(221, 221, 221, 0.5)

current pocstscss-colormin
hsla(0, 0%, 87%, 0.5)

with colord v2.9 (no spaces, no leading zero)
hsla(0,0%,87%,.5)

Don't know how to perform benchmarks here, but it also should work faster.

@omgovich
Copy link
Contributor Author

omgovich commented Oct 18, 2021

Unfortunately, I'm not able to run tests locally (don't know why). Hope you can help me.

cssnano: yarn test

/Users/omgovich/Documents/Dev/cssnano/packages/cssnano-preset-default/src/index.js
  23:29  error  Unable to resolve path to module 'postcss-colormin'  import/no-unresolved

@ludofischer
Copy link
Collaborator

Unfortunately, I'm not able to run tests locally (don't know why). Hope you can help me.

From your error message, seems like the ESLint import plugin is failing. What happens if you run yarn test:only?

@omgovich omgovich marked this pull request as draft October 18, 2021 20:38
@omgovich
Copy link
Contributor Author

yarn test:only works well. Will use this command then. Thx!

@codecov-commenter
Copy link

codecov-commenter commented Oct 19, 2021

Codecov Report

Merging #1207 (c6373c8) into master (2b5841e) will decrease coverage by 0.03%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1207      +/-   ##
==========================================
- Coverage   96.57%   96.54%   -0.04%     
==========================================
  Files         117      115       -2     
  Lines        3646     3613      -33     
  Branches     1071     1062       -9     
==========================================
- Hits         3521     3488      -33     
  Misses        117      117              
  Partials        8        8              
Impacted Files Coverage Δ
packages/postcss-colormin/src/minifyColor.js 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2b5841e...c6373c8. Read the comment docs.

@omgovich omgovich marked this pull request as ready for review October 19, 2021 16:33
@omgovich
Copy link
Contributor Author

omgovich commented Oct 19, 2021

The PR is ready. Hope you'll like the update =)

Copy link
Collaborator

@ludofischer ludofischer left a comment

Choose a reason for hiding this comment

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

Isn't it going to be a burden to handle different browser targets inside colord? What other projects are going to use this minify plugin?

@TrySound
Copy link
Collaborator

@ludofischer SVGO

@ludofischer
Copy link
Collaborator

SVGO

OK, then I guess you're prepared to handle all sort of issues :-)

@omgovich
Copy link
Contributor Author

omgovich commented Oct 19, 2021

Colord knows nothing about browsers. Its minification utility just works different ways depending on options passed into minify method. And, yeah, I'm preparing it for SVGO as well =)

image

@TrySound
Copy link
Collaborator

I guess browser support can be configured on cssnano side by passing options to minify()

@alexander-akait
Copy link
Member

I think we will need colord in rust in near future 😄

@omgovich
Copy link
Contributor Author

I guess browser support can be configured on cssnano side by passing options to minify()

It already works this way =)

@TrySound
Copy link
Collaborator

I think we will need colord in rust in near future 😄

I even know who could do it.

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.

None yet

5 participants