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.

  1. make sure require intl/intl loads core library , not of associated countries. reduce size of library from around 900kb around 150kb.

  2. use webpack's require.ensure or require([]) 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

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -