preact-cli icon indicating copy to clipboard operation
preact-cli copied to clipboard

Preact build not respecting custom browser targets

Open Haugen opened this issue 6 years ago • 1 comments

Do you want to request a feature or report a bug?

I think this might be a bug.

What is the current behaviour?

I am trying to change the browser targets for my bundles, to only support Chrome version 64 and higher. I am still a bit unclear on the exact behaviour here. If this is not a bug I would love some clarity around what is going on here.

If the current behaviour is a bug, please provide the steps to reproduce.

  • Add a .browserslistrc and include "chrome > 64"
  • Set debug to true for "@babel/preset-env" in .babelrc
  • Watch the output as you run preact build

During "compiling", the output from debug in .babelrc will show

Using targets:
{
  "chrome": "65"
}

But in a second phase, during "after chunk asset optimization", I see

Using targets:
{
  "android": "61",
  "chrome": "61",
  "edge": "16",
  "firefox": "60",
  "ios": "10.3",
  "opera": "48",
  "safari": "10.1",
  "samsung": "8.2"
}

The actual output in terms of file sizes are almost identical, but not exact. The different on the main bundle between trying to target "chrome > 64" and using the defaults is 3kb, from 354kb to 351kb. I would expect a much larger difference targeting only "Chrome > 64".

package.json file and the small configuration added: https://gist.github.com/Haugen/bac2ee3551e07ca038bcbc17e7c4f701

What is the expected behaviour?

I would expect to see "chrome": "65" as the only target even during the "after chunk asset optimization" phase of the bundling.

If this is a feature request, what is motivation or use case for changing the behaviour?

Not a feature request.

Please mention other relevant information.

I tried this with a clean project using preact create default preact-test and see similar but not identical results. Initially, with "debug: true" it prints only chrome as a target, but then prints the longer list during the last phase called "finish module graph".

Haugen avatar Sep 12 '20 23:09 Haugen

Preact-CLI does respect custom browser targets for non-esm output. The reason that you're not seeing much difference is because the majority of your bundle is made up of node_modules, which typically target ES5. By increasing your target, it's really only affecting your code which will be pretty minor.

Now, babel-plugin-esm doesn't support custom targets and it is the source of those extra targets being logged. It unfortunately has been unmaintained for years and is being stripped out of v4. As such, going to close this out as it unfortunately seems like it won't be corrected in v3.

rschristian avatar Jan 10 '23 17:01 rschristian