webpacker: babel-polyfill is not included/loaded
I noticed that the README states that babel-polyfill
is included, however there’s no reference to it in any entry points:
http://babeljs.io/docs/usage/polyfill/#usage-in-node-browserify-webpack
Is this something we must do ourselves?
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 15 (8 by maintainers)
Commits related to this issue
- Ensure `babel-polyfill` is imported (cf https://github.com/rails/webpacker/issues/523#issuecomment-321880881) — committed to TechforgoodCAST/beehive-giving by drkane 7 years ago
I think an easy change would be to indicate in the default
javascript/packs/application.js
that you need to includeimport "babel-polyfill"
. Otherwise theuseBuiltIns
option doesn’t do anything since it transforms the import statement, but doesn’t inject one.References: https://github.com/babel/babel-preset-env#usebuiltins
I corrected this by changing the
/config/webpack/shared.js
to have entry paths that include the polyfill:As @adamsanderson said, you need
import 'babel-polyfill'
to use polyfill.Including babel-polyfill in webpack
entry
like @lsanwick said is not suitable. Because they will include multiple duplicated polyfills when users use multiple packs in a view.When users use multiple packs at the same time, only one pack should import polyfill otherwise polyfill is overlapped. Or when users use each pack separately, which means one pack at a view, each one should import polyfill.
Here’s my
.babelrc
:So I guess I should follow @lsanwick’s setup? The
.babelrc
above is what I get afterwebpack:install:react
so I’m not sure why this isn’t all enabled by default.