Michael Robinson
Michael Robinson

Reputation: 29508

Webpack 2 Split Polyfills into own bundle

I'm trying to use require.ensure to cause Webpack 2 to create separate bundles containing polyfills for older browsers.

I was of the understanding that the following code would cause a new bundle whatwgFetch to be created and loaded:

require.ensure([], (require) => {
    require('whatwg-fetch')
}, 'whatwgFetch')

Webpack outputs that only one bundle is created, and when I inspect it I can see the whatwg-fetch module has been included within.

My assumptions are based on the Webpac 2 code splitting guide: https://webpack.js.org/guides/code-splitting-require/

What else should I do to cause webpack to create and load a separate bundle?

Upvotes: 1

Views: 259

Answers (1)

Michael Robinson
Michael Robinson

Reputation: 29508

I was importing the whatwg-fetch elsewhere in the application, which was causing webpack to correctly bundle it in with the rest of the code, in one single bundle.

Removing these extra imports caused it to work correctly

Upvotes: 1

Related Questions