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

Polyfills are not generated from .browserslistrc queries #1132

Closed
ekb1zh opened this issue Apr 14, 2022 · 1 comment
Closed

Polyfills are not generated from .browserslistrc queries #1132

ekb1zh opened this issue Apr 14, 2022 · 1 comment
Labels
problem: removed issue template OP removed the issue template without good cause solution: duplicate This issue or pull request already exists solution: intended behavior This is not a bug and is expected behavior solution: out-of-scope This is out of scope for this project

Comments

@ekb1zh
Copy link

ekb1zh commented Apr 14, 2022

My algorithm:

npx tsdx create mylib # run create new project and select "basic" option
cd mylib # go inside project
npm i # install packages
touch .browserslistrc # create file .browserslistrc
echo "dead" >> .browserslistrc # append query "dead" into .browserslistrc
> src/index.ts # clear src/index.ts
echo "export default () => { console.log(Object.fromEntries([[\"a\", 1]]), Promise.resolve(0)); }" >> src/index.ts # append code into src/index.ts
rm -r test # remove test folder with old code
npm run build # build project
cat dist/mylib.cjs.production.min.js # see result

Result - polyfills are absent. But they are need for execute code in dead browsers ))

These questions have been discussed in these threads .browserslistrc #951, Object.fromEntries #968, tslib #412, but I didn't find an answer to the question - if targeting .browserslist file to the old browsers, should TSDX add polyfills?

  • If yes, then this is not the case now.
  • If not, so how would such code work in older browsers?

Note:
If an incorrect request is entered into the .browserslist file, then an error will appear during the build, which means this file is included in the build, but why are polyfills not generated.

@ekb1zh ekb1zh changed the title Polyfills are not generated from requests of the .browserslistrc file Polyfills are not generated from requests of .browserslistrc file Apr 14, 2022
@ekb1zh ekb1zh changed the title Polyfills are not generated from requests of .browserslistrc file Polyfills are not generated from .browserslistrc queries Apr 14, 2022
@agilgur5 agilgur5 added problem: removed issue template OP removed the issue template without good cause solution: duplicate This issue or pull request already exists solution: intended behavior This is not a bug and is expected behavior solution: out-of-scope This is out of scope for this project labels Apr 15, 2022
@agilgur5
Copy link
Collaborator

agilgur5 commented Apr 15, 2022

  • If not, so how would such code work in older browsers?

Per #968 (comment) , polyfills are currently out-of-scope for TSDX. They were planned per that answer but were never a part of TSDX outside of regenerator/async/await. That answer also mentions how polyfills in libraries are still a topic of discussion in the JS community.
Adding the .browserslistrc as such will effectively tell @babel/preset-env to transform your code to as old as possible, but it won't insert polyfills for behavior that can't be transpiled down to an earlier environment.

The "suggested solution" in #968 (comment) is still the suggested solution in this case, that would make corejs polyfills added. usage-pure means it won't pollute the consumer environment and many consumers already have corejs installed anyway, so that is my suggestion when it comes to the topic of polyfills in libraries.
(Side note: babel-polyfills is also now a very stable collection of packages and is actually used under-the-hood of preset-env nowadays. I've also contributed a good bit to it and recently migrated it to TS)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
problem: removed issue template OP removed the issue template without good cause solution: duplicate This issue or pull request already exists solution: intended behavior This is not a bug and is expected behavior solution: out-of-scope This is out of scope for this project
Projects
None yet
Development

No branches or pull requests

2 participants