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')
      );
    }
  • 相关阅读:
    DB2
    Data Queue
    QMQY
    CMD(SA400 Command)
    Software development process
    CSS display样式
    CSS行高line-height解释
    CS和CS3知识点
    HTML图片<img>标签空白解决方法
    CS清除浮动
  • 原文地址:https://www.cnblogs.com/Answer1215/p/7265872.html
Copyright © 2011-2022 走看看