sagui
sagui copied to clipboard
Add Babel polyfill when configured
see: http://babeljs.io/docs/usage/polyfill/
Should I have it setup automatically?
I think this could be pretty useful to have by default, since we have to assume that many users of Sagui are not aware of the differences in ES feature support in the different environments. It feels that the polyfill goes hand to hand with using Babel.
That said I also would like a flag to disable it if needed.
An alternative: https://github.com/Financial-Times/polyfill-service
I second @xaviervia's opinion about polyfill being enabled by default.
Since some of the sagui's dependencies depend upon new ES features (css-modules depending on Object.assign), it would make sense to include it out of the box. I'm having my website breaking on older browsers, which could have easily been avoided using polyfill. We could also avoid issues like this: http://www.andrewzey.com/google-seo-with-create-react-app-fixing-the-hidden-gotcha/
Also, what would be the preferred way to include polyfill for now?
I think the simplest way right now is to install it in the project (npm install babel-polyfill
) and include it as the first line in the entrypoint (ie. import 'babel-polyfill'
in the src/index.js
).
It might be good to have that as part of the index.js
template, although that would imply installing the polyfill automatically and I am not sure how that would work.
The alternative is to make it part of the build so that Sagui concatenates the polyfill with the JS entrypoints by default. That might be easier to set up than adding it in the template, and it's consistent with Sagui's philosophy of making it easy to consumers. If we do this we should of course include a flag in the configuration to disable the polyfill, since it's pretty heavy and some consumers might not want it.
You might also consider using babel-preset-env. This way the user can configure which environments to support.
that is awesome @fhelwanger! sounds like something we should consider having by default!