[React Intl] Use Webpack to Conditionally Include an Intl Polyfill for Older Browsers
2024-08-23 14:06:53
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')
);
}
最新文章
- ORACLE添加表约束的语法示例
- JAVA中ArrayList用法
- ren
- hbase meta表修复
- SpingMVC ModelAttribute的用法
- 【Away3D代码解读】(五):动画模块及骨骼动画
- Java笔记(二十八)&hellip;&hellip;IO流下 IO包中其他常用类以及编码表问题
- hdu 1015 dfs
- Scrum 学习笔记
- 使用SQL Server 2008远程链接时SQL数据库不成功的解决方法
- Linux企业级项目实践之网络爬虫(14)——使用正则表达式抽取HTML正文和URL
- Grub启动配置文件
- Spring Boot学习总结一
- canvas(三) star- demo
- Javascript高级编程学习笔记(12)—— 引用类型(1)Object类型
- centos 7 防火墙的使用 firewalld
- 域名、ip、以及通过域名访问网站、虚拟主机
- https://www.cnblogs.com/zy-jiayou/p/7661415.html
- Chrome nacl开启
- iOS 开发中,关于xxx.xcodeproj 文件冲突的解决方案 (以后谁不会了,直接将连接给他)
热门文章
- iOS项目开发实战——学会使用TableView列表控件(二)
- C#实现窗口拖动时各个控件同比自己主动放缩大小
- windows下搭建hadoop-2.6.0本地idea开发环境
- vim 基础学习之可视模式
- 下载安装与配置Excel 2013数据挖掘加载项(SQL Server 2012 SP1 + SQLServer2012_DMAddin.msi)
- 阅读笔记—JSP
- CSDN的个人主页如何添加微信二维码
- C++里面virtual函数及虚表大小
- Java 批量修改文件后缀
- Direct2D开发:Direct2D 和 GDI 互操作性概述