saguijs / sagui

:monkey: Front-end tooling in a single dependency
http://sagui.js.org/
MIT License
669 stars 32 forks source link

Add Babel polyfill when configured #21

Open pirelenito opened 8 years ago

pirelenito commented 8 years ago

see: http://babeljs.io/docs/usage/polyfill/

pirelenito commented 8 years ago

Should I have it setup automatically?

xaviervia commented 7 years ago

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.

pirelenito commented 7 years ago

An alternative: https://github.com/Financial-Times/polyfill-service

karthikiyengar commented 7 years ago

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?

xaviervia commented 7 years ago

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.

fhelwanger commented 7 years ago

You might also consider using babel-preset-env. This way the user can configure which environments to support.

pirelenito commented 7 years ago

that is awesome @fhelwanger! sounds like something we should consider having by default!