javascript - Intl.js polyfill/shim with webpack? -
i'm using react-intl webpack , need intl shim support safari , ie, don't want load browsers support intl spec.
the polyfill pretty huge (900kb), how can ensure gets loaded in browsers don't support already?
there few things need do.
make sure require
intl/intl
loads core library , not of associated countries. reduce size of library from around 900kb around 150kb.use webpack's
require.ensure
orrequire([])
functions dynamically require intl.js when needed. create separate bundle intl.js file, loaded on as-needed basis.
lib/shim.js
// shim intl needs loaded dynamically // callback when we're done represent // kind of "shimready" event module.exports = function(callback) { if (!window.intl) { require(['intl/intl'], function(intl) { window.intl = intl; callback(); }); } else { settimeout(callback, 0); // force async } };
app.js
var shimready = require('lib/shim'); shimready(startapp);
note: may need access country-specific information , properties. basic needs didn't require data, if sure read section on intl.js website loading locale data.
Comments
Post a Comment