esbuild-loader icon indicating copy to clipboard operation
esbuild-loader copied to clipboard

feat: browserslist support

Open privatenumber opened this issue 3 years ago • 5 comments

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:

privatenumber avatar May 03 '21 08:05 privatenumber

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

marcofugaro avatar Oct 18 '21 09:10 marcofugaro

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

jaxonly avatar Nov 29 '21 04:11 jaxonly

@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.

marcofugaro avatar Nov 29 '21 22:11 marcofugaro

As mentioned in https://github.com/evanw/esbuild/issues/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.

TrevorSayre avatar Mar 08 '22 14:03 TrevorSayre

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.

silverwind avatar Apr 01 '23 04:04 silverwind