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

Optionally require es6-promise and isomorphic-fetch #369

Open
moretti opened this issue Jul 27, 2015 · 2 comments
Open

Optionally require es6-promise and isomorphic-fetch #369

moretti opened this issue Jul 27, 2015 · 2 comments

Comments

@moretti
Copy link
Contributor

moretti commented Jul 27, 2015

It would be nice if we could optionally avoid to polyfill Promise and window.fetch.
The latest versions of Firefox, Chrome and Opera natively support Promises and window.fetch, so it seems unnecessary. I recently started loading polyfills on demand with webpack in order to reduce the size of the main bundle.

I'm proposing the following structure

  • marty.js (or maybe marty-without-polyfills.js): equivalent to the current file, but without polyfills
  • polyfills.js: a file containing all polyfills
  • index.js (or maybe marty-with-polyfills.js): the entry point of the project with the old behavior

In this way it would be possible not to load polyfills by creating an alias.
With webpack:

module.exports = {
  // ...
  resolve: {
    alias: {
      'marty': 'marty/marty-without-polyfills.js'
    }
  }
};

With browserify:

browserify --require marty:marty/marty-without-polyfills.js
@taion
Copy link
Member

taion commented Jul 31, 2015

Do you have any examples of projects that are structured this way that we can look at?

@moretti
Copy link
Contributor Author

moretti commented Jul 31, 2015

I created the following example:

https://github.com/moretti/webpack-polyfills-on-demand

If you clone it and run npm start you will notice that polyfills for fetch and Promise are loaded on demand.
For example, Safari 8 will request 2.bundle.js because it doesn't have a native window.fetch implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants