소스 검색

fix: 尝试修复br压缩插件加载错误

BaiLuoYan 4 주 전
부모
커밋
4b26441b56
6개의 변경된 파일4694개의 추가작업 그리고 3441개의 파일을 삭제
  1. 1 0
      package.json
  2. 4668 3427
      pnpm-lock.yaml
  3. 2 1
      src/i18n/index.ts
  4. 8 0
      src/locales/dirMap.ts
  5. 3 12
      src/utils/mdLoader.ts
  6. 12 1
      vite.config.ts

+ 1 - 0
package.json

@@ -76,6 +76,7 @@
     "@types/react-dom": "^18.2.0",
     "@typescript-eslint/eslint-plugin": "^8.27.0",
     "@typescript-eslint/parser": "^8.27.0",
+    "@vitejs/plugin-legacy": "6.1.1",
     "@vitejs/plugin-react": "^4.3.4",
     "autoprefixer": "10.4.17",
     "boxen": "^8.0.1",

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 4668 - 3427
pnpm-lock.yaml


+ 2 - 1
src/i18n/index.ts

@@ -119,7 +119,8 @@ i18n.use(LanguageDetector)
 */
 
 // ****************** 使用 LanguageDetector、支持按需加载翻译文件 时 i18n 的配置方法 ******************
-const modules = import.meta.glob('@/locales/*.ts');
+// 匹配 locales 下所有 .ts,显式排除 dirMap.ts(fast-glob 否定语法)
+const modules = import.meta.glob(['@/locales/*.ts', '!@/locales/dirMap.ts']);
 const languageFiles: Record<string, () => Promise<any>> = {};
 const languageCodes = new Set<string>();
 Object.entries(modules).forEach(([path]) => {

+ 8 - 0
src/locales/dirMap.ts

@@ -0,0 +1,8 @@
+/**
+ * 各语言排版方向,供 mdLoader 等使用,避免 eager 引用完整 locale 导致与 i18n 按需加载冲突。
+ */
+export const localeDir: Record<string, 'ltr' | 'rtl'> = {
+    'zh-CN': 'ltr',
+    'en-US': 'ltr',
+    'fa-IR': 'rtl',
+};

+ 3 - 12
src/utils/mdLoader.ts

@@ -22,18 +22,9 @@ Object.keys(rawMdModules).forEach((key) => {
     }
 });
 
-const localeModules = import.meta.glob<{ default?: { DIR?: string } }>('@/locales/*.ts', {
-    eager: true,
-});
-const dirByLang: Record<string, 'ltr' | 'rtl'> = {};
-Object.keys(localeModules).forEach((key) => {
-    const match = key.match(/\/([\w-]+)\.ts$/);
-    if (match) {
-        const lang = match[1]!;
-        const dir = localeModules[key]?.default?.DIR;
-        if (dir === 'ltr' || dir === 'rtl') dirByLang[lang] = dir;
-    }
-});
+import { localeDir } from '@/locales/dirMap';
+
+const dirByLang: Record<string, 'ltr' | 'rtl'> = { ...localeDir };
 
 export interface LoadMdByLangOptions {
     /** 占位符替换:key 为 MD 中的占位符(如 [Insert Date]),value 为替换后的字符串 */

+ 12 - 1
vite.config.ts

@@ -3,6 +3,7 @@ import { defineConfig, loadEnv } from 'vite';
 import removeConsole from 'vite-plugin-remove-console';
 import topLevelAwait from 'vite-plugin-top-level-await';
 import wasm from 'vite-plugin-wasm';
+import legacy from '@vitejs/plugin-legacy';
 
 import { viteBuildInfo } from './build/buildInfo';
 import { configCompressPlugin } from './build/compress';
@@ -20,6 +21,15 @@ export default defineConfig(({ mode }) => {
             react(),
             wasm(),
             topLevelAwait(),
+            legacy({
+                targets: [
+                    'chrome >= 87',
+                    'safari >= 13',
+                    'firefox >= 78',
+                    'edge >= 88',
+                    'not IE 11',
+                ],
+            }),
             isProd &&
                 removeConsole({
                     includes: ['log', 'warn'],
@@ -82,7 +92,8 @@ export default defineConfig(({ mode }) => {
         build: {
             outDir: 'dist',
             sourcemap: !isProd,
-            target: ['es2015', 'chrome87', 'safari13', 'firefox78', 'edge88'],
+            // target 由 plugin-legacy 的 targets 控制,不在此设置避免被覆盖并触发警告
+            // target: ['es2015', 'chrome87', 'safari13', 'firefox78', 'edge88'],
             cssTarget: ['chrome87', 'safari13', 'firefox78', 'edge88'],
             rollupOptions: {
                 output: {

이 변경점에서 너무 많은 파일들이 변경되어 몇몇 파일들은 표시되지 않았습니다.