zoukankan      html  css  js  c++  java
  • [React Intl] Use Webpack to Conditionally Include an Intl Polyfill for Older Browsers

    Some browsers, such as Safari < 10 & IE < 11, do not support the JavaScript Internationalization API, which react-intl depends on. In order to support these browsers, we’ll conditionally include an Intl polyfill using webpack require.ensure. This ensures only browsers that need the polyfill incur the extra load.

    if (!window.Intl) {
      require.ensure([
        'intl',
        'intl/locale-data/jsonp/en.js',
        'intl/locale-data/jsonp/fr.js',
        'intl/locale-data/jsonp/es.js'
      ], (require) => {
        require('intl');
        require('intl/locale-data/jsonp/en.js');
        require('intl/locale-data/jsonp/fr.js');
        require('intl/locale-data/jsonp/es.js');
    
        runApp();
      })
    } else {
      runApp();
    }
    
    function runApp() {
      addLocaleData([...en, ...fr, ...es]);
    
      let locale = (navigator.languages && navigator.languages[0])
        || navigator.language
        || navigator.userLanguage
        || 'en-US';
    
      ReactDOM.render(
        <IntlProvider locale={locale} messages={flattenMessages(messages[locale])}>
          <App />
        </IntlProvider>,
        document.getElementById('root')
      );
    }
  • 相关阅读:
    Flink批处理读取Hive写入MySql
    数组与链表的优缺点
    Flink任务暂停重启
    Flink优化总结
    Flink集群监控
    flink连接器-流处理-读写redis
    Flink连接器-批处理-读写Hbase
    flink on yarn
    java的常量定界符
    特殊注释的使用
  • 原文地址:https://www.cnblogs.com/Answer1215/p/7265872.html
Copyright © 2011-2022 走看看