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

feat: browserslist support #162

Open
privatenumber opened this issue May 3, 2021 · 5 comments
Open

feat: browserslist support #162

privatenumber opened this issue May 3, 2021 · 5 comments

Comments

@privatenumber
Copy link
Owner

privatenumber commented May 3, 2021

Is your feature request related to a problem? Please describe.

Usually browser support is defined in a browserslist file that all preprocessors look at. However, you must pass in a target manually to esbuild-loader.

Describe the solution you'd like

Automatic detection of browserslist to determine target.

Describe alternatives you've considered

Additional context

References:

@marcofugaro
Copy link

I've made a package that autodetects your browserslist config and returns an esbuild-compatible browsers list you can pass to the target option.

https://github.com/marcofugaro/browserslist-to-esbuild

@jaxonly
Copy link

jaxonly commented Nov 29, 2021

This does not seem to work for mobile
I tried the conversion using the following rule , and it returned null

iOS >= 9
Android >= 4.0

@marcofugaro

@marcofugaro
Copy link

marcofugaro commented Nov 29, 2021

@jaxonly fixed in version 1.1.0.
Keep in mind that Android 4.0 refers to the legacy android webview, which is not supported by esbuild target option.

If you put Android >= 4.0 in browserslistToEsbuild, it gets automatically bumped to Android 5.0, which is the version where Chrome was introduced as an android webview. Sources here.

@TrevorSayre
Copy link

TrevorSayre commented Mar 8, 2022

As mentioned in evanw/esbuild#121 we have found https://github.com/nihalgonsalves/esbuild-plugin-browserslist from @nihalgonsalves to work quite nicely.

const { resolveToEsbuildTarget } = require('esbuild-plugin-browserslist');
...
// defaults to: browserslist('> 0.5%, last 2 versions, Firefox ESR, not dead')
const targets = resolveToEsbuildTarget(browserslist());

We then use targets for ESBuildMinifyPlugin and esbuild-loader.

@silverwind
Copy link
Contributor

silverwind commented Apr 1, 2023

If this will be added, keep it opt-in please so the plugin stays lightweight. I personally don't consider needing browserlist in new projects and see it as a legacy mechanism.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants