What is the recomended way to use with core-js with WebPack 3? I was thinking of using the Webpack ProvidePlugin plugin like so:
new webpack.ProvidePlugin({
Promise: 'core-js/fn/promise'
}),
However, I'm not sure how to then also include all of the other polyfills like String.prototype.includes. Is there a list of them available that I can add to the ProvidePlugin or am I going about this in the wrong way? Ideally you'd only want to import something if you use it, the alternative is to just import 'core-js'.
@RehanSaeed
We create a polyfills.js like the following:
import 'core-js/fn/promise'
import 'core-js/fn/string/includes'
and add it our webpack entry point:
entry: ['./polyfills.js', './index.js']
You could also do:
entry: ['core-js/fn/promise', 'core-js/fn/string/includes', './app/js']
the core-js/fn/* modules patch the global namespace (for example core-js/fn/promise changes the global Promise), so there is no need to use the ProvidePlugin plugin.
@RehanSaeed I think that solution like ProvidePlugin are not useful because that can determinate only little part of features. I prefer way like proposes @michael-wolfenden. Also, you can try babel-preset-env with useBuiltIns: 'usage' option which injects required part of core-js.
Most helpful comment
@RehanSaeed
We create a
polyfills.jslike the following:and add it our webpack
entrypoint:You could also do:
the
core-js/fn/*modules patch the global namespace (for examplecore-js/fn/promisechanges the globalPromise), so there is no need to use theProvidePluginplugin.