-
Notifications
You must be signed in to change notification settings - Fork 215
fixes #118: ignoring the inclusion of all locale date when bundling the polyfill with browserify/webpack. #121
Conversation
…n bundling the polyfill with browserify/webpack.
@gpbl, can you try this out before we merge it? |
Perfect 👍 with this change I can now require if (!window.Intl)
require.ensure(["intl"], (require) => {
require("intl"); // window.Intl is available
});
} |
fixes #118: ignoring the inclusion of all locale date when bundling the polyfill with browserify/webpack.
How do you guys load the locale data? |
@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 |
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');
} |
@madebyherzblut even better you can just require require.ensure(['intl'], require => {
require('intl');
require('intl/locale-data/jsonp/en.js');
cb();
}, 'intl-polyfill'); |
Sweet, thank you @gpbl 👍 |
👍 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'); |
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' . Has anyone else encountered this issue . If anyone has any ideas could you please give me some advice. Thanks |
I haven't, but I will highly recommend the polyfill service instead, unless you're working on an intranet kind of app. |
This will facilitate the optional fetching/execution of the polyfill when using
require.ensure()
in webpack/browerify, e.g.: