Skip to content

Instantly share code, notes, and snippets.

@sderosiaux
Forked from ryanflorence/polyfills.js
Last active January 27, 2016 21:35
Show Gist options
  • Select an option

  • Save sderosiaux/3d49105cb46495addd2a to your computer and use it in GitHub Desktop.

Select an option

Save sderosiaux/3d49105cb46495addd2a to your computer and use it in GitHub Desktop.
Webpack: inject bundle (or polyfills) on the fly
  • promise-loader returns a promise require("promise?bluebird!./file.js")(file => ...);
  • bundle-loader returns a callback require("bundle!./file.js")(file => ...);

Both are using require.ensure() behind the scene.

Manually :

if (typeof Promise === 'undefined') {
  require.ensure([], (require) => {
    require('imports?this=>window!es6-promise')
  })
}

if (typeof fetch === 'undefined') {
  require.ensure([], (require) => {
    require('imports?self=>window!whatwg-fetch')
  })
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment