exclude a bunch of polyfill locales (#10111)

This commit is contained in:
Bram Kragten 2021-09-30 16:43:46 +02:00 committed by GitHub
parent 41a7b42037
commit e023d60be7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -15,8 +15,6 @@ export interface FormatsType {
time: FormatType; time: FormatType;
} }
let loadedPolyfillLocale: Set<string> | undefined;
const polyfillPluralRules = shouldPolyfillPluralRules(); const polyfillPluralRules = shouldPolyfillPluralRules();
const polyfillRelativeTime = shouldPolyfillRelativeTime(); const polyfillRelativeTime = shouldPolyfillRelativeTime();
const polyfillDateTime = shouldPolyfillDateTime(); const polyfillDateTime = shouldPolyfillDateTime();
@ -41,7 +39,6 @@ let polyfillLoaded = polyfills.length === 0;
export const polyfillsLoaded = polyfillLoaded export const polyfillsLoaded = polyfillLoaded
? undefined ? undefined
: Promise.all(polyfills).then(() => { : Promise.all(polyfills).then(() => {
loadedPolyfillLocale = new Set();
polyfillLoaded = true; polyfillLoaded = true;
// Load English so it becomes the default // Load English so it becomes the default
return loadPolyfillLocales("en"); return loadPolyfillLocales("en");
@ -132,19 +129,28 @@ export const computeLocalize = async (
}; };
export const loadPolyfillLocales = async (language: string) => { export const loadPolyfillLocales = async (language: string) => {
if (!loadedPolyfillLocale || loadedPolyfillLocale.has(language)) { if (!polyfillsLoaded) {
return; return;
} }
loadedPolyfillLocale.add(language); await polyfillsLoaded;
try { try {
if (polyfillPluralRules) { if (polyfillPluralRules) {
await import(`@formatjs/intl-pluralrules/locale-data/${language}`); await import(
/* webpackExclude: /.+-.+\.js$/ */
`@formatjs/intl-pluralrules/locale-data/${language}`
);
} }
if (polyfillRelativeTime) { if (polyfillRelativeTime) {
await import(`@formatjs/intl-relativetimeformat/locale-data/${language}`); await import(
/* webpackExclude: /.+-.+\.js$/ */
`@formatjs/intl-relativetimeformat/locale-data/${language}`
);
} }
if (polyfillDateTime) { if (polyfillDateTime) {
await import(`@formatjs/intl-datetimeformat/locale-data/${language}`); await import(
/* webpackExclude: /.+-.+\.js$/ */
`@formatjs/intl-datetimeformat/locale-data/${language}`
);
} }
} catch (_e) { } catch (_e) {
// Ignore // Ignore