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

Lower modern yet 12 y.o. CSS properties and values to vendor-prefixed versions #3122

Closed
Signez opened this issue May 18, 2023 · 9 comments
Closed

Comments

@Signez
Copy link

Signez commented May 18, 2023

Vendor-prefixing is a deprecated practice that seems to be on the decline, yet this article on CSS-Tricks "Is Vendor-Prefixing dead?" counted 31 "features" that still required prefixing in 2021.

Some of those features, like the mask-image properties, are quite commonly used on the web and are available to web authors for more than 12 years. In this mask-image example, Chrome doesn't seems to have short term plans to get rid of those prefixes (it doesn't seems to be part of Interop 2023), so it will be needed for years to come.

Prefixes are cumbersome to add manually — but it is quite cumbersome to automate their additions in a esbuild-based toolchain too, as it means installing PostCSS packages and load a PostCSS plugin in esbuild solely to use autoprefixer.

Vendor-prefixing doesn’t seems to be a moving target anymore, and will be required for years to come. Having a way to use the recent target / supported options to handle those properties and values, at least the few that only needs a prefix (without more syntax changes), would save developers hours of work and megabytes of toolchains to download! ✨

@Signez
Copy link
Author

Signez commented May 18, 2023

(As a little addendum: mask-image seems to be a niche addition, but for multiple reasons, it is the only way we know to add icons as pseudo-elements which colors follow currentColor or a custom property color, which is a very common occurrence in the projects I had the chance to work on.)

@JoshuaWise
Copy link

I would also like to see this feature. I see it as a missing feature, because I expect my build system to transpile my CSS into being brower-compatible (based on the browser target list), just as it's done for JavaScript. Currently I'm hacking around this by using PostCSS as a post-build step, but PostCSS is insanely slow. Even just require('postcss-preset-env') takes 250ms!

evanw added a commit that referenced this issue Jun 26, 2023
@evanw evanw closed this as completed in 9ed47f5 Jun 26, 2023
@evanw
Copy link
Owner

evanw commented Jun 26, 2023

I've added some vendor prefixing to esbuild. Here's the current list of automatically-prefixed properties:

  • appearance: *; => -webkit-appearance: *; -moz-appearance: *;
  • backdrop-filter: *; => -webkit-backdrop-filter: *;
  • background-clip: text => -webkit-background-clip: text;
  • box-decoration-break: *; => -webkit-box-decoration-break: *;
  • clip-path: * => -webkit-clip-path: *;
  • font-kerning: *; => -webkit-font-kerning: *;
  • hyphens: *; => -webkit-hyphens: *;
  • initial-letter: *; => -webkit-initial-letter: *;
  • mask-image: *; => -webkit-mask-image: *;
  • mask-origin: *; => -webkit-mask-origin: *;
  • mask-position: *; => -webkit-mask-position: *;
  • mask-repeat: *; => -webkit-mask-repeat: *;
  • mask-size: *; => -webkit-mask-size: *;
  • position: sticky; => position: -webkit-sticky;
  • print-color-adjust: *; => -webkit-print-color-adjust: *;
  • tab-size: *; => -moz-tab-size: *; -o-tab-size: *;
  • text-decoration-color: *; => -webkit-text-decoration-color: *; -moz-text-decoration-color: *;
  • text-decoration-line: *; => -webkit-text-decoration-line: *; -moz-text-decoration-line: *;
  • text-decoration-skip: *; => -webkit-text-decoration-skip: *;
  • text-emphasis-color: *; => -webkit-text-emphasis-color: *;
  • text-emphasis-position: *; => -webkit-text-emphasis-position: *;
  • text-emphasis-style: *; => -webkit-text-emphasis-style: *;
  • text-orientation: *; => -webkit-text-orientation: *;
  • text-size-adjust: *; => -webkit-text-size-adjust: *; -ms-text-size-adjust: *;
  • user-select: *; => -webkit-user-select: *; -moz-user-select: *; -ms-user-select: *;

Compatibility data has been copied from https://caniuse.com. This should get things started, and support for more CSS properties can be added in the future as appropriate.

Hopefully all of these transformations were done correctly. I tested some of them but not all of them. I know of a few special cases (e.g. user-select: none => -moz-user-select: -moz-none) but there are surely others that I missed. Let me know if anything seems off about these transforms or if any other transforms are important for you.

@Signez
Copy link
Author

Signez commented Jun 26, 2023

Thanks! It's so awesome to see this feature implemented that quickly ✨

@JoshuaWise
Copy link

JoshuaWise commented Jun 26, 2023

This is great! 🥳

It may be worth looking at Autoprefixer as a reference for all the different properties that people expect, since that project has years of history and development for this exact purpose:

https://github.com/postcss/autoprefixer/blob/main/data/prefixes.js

@silverwind
Copy link

Is there an opt-out option to this?

@evanw
Copy link
Owner

evanw commented Jun 27, 2023

If you don't set the target environment, then esbuild won't add any prefixes.

@silverwind
Copy link

If you don't set the target environment, then esbuild won't add any prefixes.

If I just set a JS-only target like es2020 would esbuild derive browsers from it for this feature?

@evanw
Copy link
Owner

evanw commented Jun 27, 2023

No, only browser targets apply to CSS. Other non-browser targets such as node also don't affect CSS.

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

No branches or pull requests

4 participants