Skip to content
This repository was archived by the owner on Apr 14, 2021. It is now read-only.

fixes #118: ignoring the inclusion of all locale date when bundling the polyfill with browserify/webpack. #121

Merged
merged 2 commits into from
Jul 11, 2015

Conversation

caridy
Copy link
Collaborator

@caridy caridy commented Jul 9, 2015

This will facilitate the optional fetching/execution of the polyfill when using require.ensure() in webpack/browerify, e.g.:

if (!window.Intl) {
    // hello safari
        require.ensure(['intl'], (require) => {
            window.Intl = require('intl');
            // locale data should be also included here...
            runMyApp()
        }, "IntlBundle");
else {
      // hello chrome, ie, etc.!
      runMyApp()
}

…n bundling the polyfill with browserify/webpack.
@caridy
Copy link
Collaborator Author

caridy commented Jul 9, 2015

@gpbl, can you try this out before we merge it?

@gpbl
Copy link

gpbl commented Jul 10, 2015

Perfect 👍 with this change I can now require intl without the need to access its internals:

if (!window.Intl)
     require.ensure(["intl"], (require) => {
        require("intl"); // window.Intl is available
      });
}

caridy added a commit that referenced this pull request Jul 11, 2015
fixes #118: ignoring the inclusion of all locale date when bundling the polyfill with browserify/webpack.
@caridy caridy merged commit 236a9f2 into andyearnshaw:master Jul 11, 2015
@caridy caridy deleted the webpack branch July 11, 2015 00:04
@madebyherzblut
Copy link

How do you guys load the locale data?

@caridy
Copy link
Collaborator Author

caridy commented Jul 14, 2015

@madebyherzblut I suspect that if you support a small number of locales, you will probably bundle those locales with intl polyfill into a single file, and you require them all after requiring intl. If your app supports many different locales, then you will probably need to load the current locale individually (using require.ensure) and requiring it right after intl.

@madebyherzblut
Copy link

Thanks for the tips, @caridy. In case anyone else is wondering, here is the snippet I am using:

export default function shim(cb) {
  let root = window ? window : global;
  if (root && root.Intl) {
    return setTimeout(cb, 0);
  }

  require.ensure(['intl'], require => {
    window.Intl = require('intl');
    require('intl/locale-data/jsonp/en.js');
    cb();
  }, 'intl-polyfill');
}

@gpbl
Copy link

gpbl commented Jul 20, 2015

@madebyherzblut even better you can just require intl without assigning window.Intl:

 require.ensure(['intl'], require => {
    require('intl');
    require('intl/locale-data/jsonp/en.js');
    cb();
  }, 'intl-polyfill');

@madebyherzblut
Copy link

Sweet, thank you @gpbl 👍

@oliviertassinari
Copy link

👍 for this PR

For a multi context, you can use :

 var intlRequire = require.context('promise?lie!intl/locale-data/jsonp', false, /^.\/(en|fr).js$/);
 var intlPromise = intlRequire('./' + _current + '.js');

@donnrri
Copy link

donnrri commented Sep 27, 2015

Hi If yu can assist me I would be very grateful. I have to load the polyfill in IE8, using the conditional loading as described above I get an error , 'expected identifier' .
The error occurs within the following code:
finally{r()}})},t}function a(n){var
e={_acceptedDependencies:{},_declinedDependencies:{},_selfAccepted:!1,_selfDeclined:!1,_disposeHandlers:

Has anyone else encountered this issue . If anyone has any ideas could you please give me some advice. Thanks

@caridy
Copy link
Collaborator Author

caridy commented Sep 27, 2015

I haven't, but I will highly recommend the polyfill service instead, unless you're working on an intranet kind of app.

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

Successfully merging this pull request may close these issues.

5 participants