create-react-app by default uses browserslist, but as I see it works only for *.js files (I'm not so sure), for *.ts no difference.
My env (generated by create-react-app):
Code of project consists of *.ts / *.tsx files only.
I've tried to add Object.entries polyfill by:
browserslist in package.json by adding IE 9, chrome >20, etc... - But to no avail (dist was not changed)compilerOptions.target in tsconfig.json to es5 - But to no avail (dist was not changed)compilerOptions.lib in tsconfig.json new values: es5,es6,es7, etc... - But to no avail (dist was not changed)Only adding import 'react-app-polyfill/stable'; gives me Object.entries polyfill, but with ~600kb of other polyfills :(
Questions:
*.js files?My main mistake:
When editing the browserslist config, you may notice that your changes don't get picked up right away. This is due to an issue in babel-loader not detecting the change in your package.json. A quick solution is to delete the node_modules/.cache folder and try again.
rm -rf node_modules/.cache before build given completely different result.
Is browserslist in create-react-app project uses ONLY for *.js files?
Nope, this works with *.ts / *.tsx too.
Is there currently no way to use browserslist for auto-adding polyfills for compiling TypeScript project?
Polyfills does't includes by default, need to use react-app-polyfill
react-app-polyfill doc:
You can also polyfill stable language features not available in your target browsers. If you're using this in Create React App, it will automatically use the browserslist you've defined to only include polyfills needed by your target browsers when importing the stable polyfill.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With