various bundle optimizations (#1549)

* fix: missing "@element-plus/icons-vue" dependency

* fix: update vite (40% faster builds)

* fix: don't include sentry in non-nightly builds

* fix: swap to variable fonts & don't include font files in repo

* fix: lazy load languages to not keep them in memory

* nit: revert vite to stable

* nit: retain `.json` message files in bundle

* nit: remove bundle analyzer

* fix: availableLocales does not include unloaded locales
This commit is contained in:
Aries
2026-01-03 23:51:00 -07:00
committed by GitHub
parent 327e7d9b58
commit b02d287190
38 changed files with 574 additions and 619 deletions

View File

@@ -1,37 +1,44 @@
const langCodes = [
'cs',
'en',
'es',
'fr',
'hu',
'ja',
'ko',
'pl',
'pt',
'ru',
'th',
'vi',
'zh-CN',
'zh-TW'
];
const elementPlusStrings = {
// Vite does not support dynamic imports to `node_modules`.
// https://github.com/rollup/plugins/tree/master/packages/dynamic-import-vars#limitations
cs: () => import('element-plus/es/locale/lang/cs'),
en: () => import('element-plus/es/locale/lang/en'),
es: () => import('element-plus/es/locale/lang/es'),
fr: () => import('element-plus/es/locale/lang/fr'),
hu: () => import('element-plus/es/locale/lang/hu'),
ja: () => import('element-plus/es/locale/lang/ja'),
ko: () => import('element-plus/es/locale/lang/ko'),
pl: () => import('element-plus/es/locale/lang/pl'),
pt: () => import('element-plus/es/locale/lang/pt'),
ru: () => import('element-plus/es/locale/lang/ru'),
th: () => import('element-plus/es/locale/lang/th'),
vi: () => import('element-plus/es/locale/lang/vi'),
'zh-CN': () => import('element-plus/es/locale/lang/zh-cn'),
'zh-TW': () => import('element-plus/es/locale/lang/zh-tw')
};
async function getLocalizationStrings() {
const urlPromises = Promise.all(
langCodes.map((code) =>
import(`./${code}.json?url`).then((m) => m.default)
)
);
const urls = await urlPromises;
const fetchPromises = Promise.all(
urls.map((url) => fetch(url).then((res) => res.json()))
);
const results = await fetchPromises;
const entries = langCodes.map((code, index) => {
return [code, results[index]];
});
return Object.fromEntries(entries);
async function getElementPlusStrings(code) {
return (await elementPlusStrings[code]()).default;
}
export { getLocalizationStrings };
async function getLocalizedStrings(code) {
const localizedStringsUrl = new URL(`./${code}.json`, import.meta.url).href;
const localizedStrings = await fetch(localizedStringsUrl).then((response) => response.json())
return {
...localizedStrings,
elementPlus: await getElementPlusStrings(code)
};
}
const languageNames = import.meta.glob('./*.json', {
eager: true,
import: 'language'
});
function getLanguageName(code) {
return languageNames[`./${code}.json`];
}
export * from "./locales";
export { getLanguageName, getLocalizedStrings };

View File

@@ -0,0 +1,17 @@
// Separate file, to be importable in `vite.config.js`.
export const languageCodes = [
'cs',
'en',
'es',
'fr',
'hu',
'ja',
'ko',
'pl',
'pt',
'ru',
'th',
'vi',
'zh-CN',
'zh-TW'
];