Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow build without es6 promise polyfill #11

Closed
bitinn opened this issue Sep 19, 2014 · 6 comments

Comments

@bitinn
Copy link

commented Sep 19, 2014

Great stuff! This seem to be the only lib I found that actually use native es6 promise with proper responseType for xhr2.

One suggestion: we actually manage polyfills separately, would be great to have a build without polyfill bundled to save some bytes.

@mzabriskie

This comment has been minimized.

Copy link
Member

commented Sep 19, 2014

@bitinn this is a great idea. I will see about tweaking the build to provide an option that excludes the polyfill.

mzabriskie added a commit that referenced this issue Sep 28, 2014

@mzabriskie mzabriskie closed this Sep 28, 2014

@wmadden

This comment has been minimized.

Copy link

commented Aug 24, 2015

@mzabriskie this still causes problems in our project which imports axios indirectly, i.e. we import another library which imports axios. In our case we're building our project using webpack which is eventually importing axios, and naturally we haven't set up the es6-promise external you have in your config.

A better approach might be to check if a native Promise implementation exists at runtime, because es6-promise's polyfill method will just override anything that already exists in the global namespace.

@wmadden

This comment has been minimized.

Copy link

commented Aug 24, 2015

E.g.

var es6Promise = require('es6-promise');
if (!global.Promise) {
  es6Promise.polyfill();
}

Although I'd question whether it's valuable for axios to be supplying the polyfill at all. It seems like it's useful exclusively for when the library's loaded in isolation - which won't happen in any more complex project with its own build system.

In that case it might be better to include a bootstrapping file only for your dist webpack entry, and do the polyfilling there.

Anyone that imports axios from source can be reasonably expected to have polyfilled their environment to include a Promise implementation.

@mzabriskie

This comment has been minimized.

Copy link
Member

commented Sep 11, 2015

@wmadden the next release will remove the es6-promise dependency all together. This will require you to either have an environment that natively offers Promise, or polyfill it yourself. Will that work for your use case?

@wmadden

This comment has been minimized.

Copy link

commented Sep 13, 2015

Great, thanks very much @mzabriskie!

@gbrassey

This comment has been minimized.

Copy link

commented Jan 7, 2016

For webpack users looking for a way to polyfill Promises. Expose loader does the job nicely without requiring a boostrapped entry: 'expose?Promise!bluebird'

var CommonsChunkPlugin = require('webpack/lib/optimize/CommonsChunkPlugin');

module.exports = {
  entry: {
    'appBundle': './appEntry.js',
    vendors: [
      'expose?Promise!bluebird',
      'axios',
    ],
  },
  plugins: [
    new CommonsChunkPlugin('vendors', './commonVendors.js'),
  ],
  module: {
    loaders: [
      {
        test: /\.jsx?$/,
        exclude: /(node_modules)/,
        loader: 'babel',
      },
    ],
  },
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.