martyjs / marty

A Javascript library for state management in React applications
http://martyjs.org
MIT License
1.09k stars 77 forks source link

Optionally require `es6-promise` and `isomorphic-fetch` #369

Open moretti opened 8 years ago

moretti commented 8 years ago

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

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 commented 8 years ago

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

moretti commented 8 years ago

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.