Просмотр исходного кода

feat: optimize date-fns imports by switching to individual subpath imports for reduced module size

Yuki Takei 1 месяц назад
Родитель
Сommit
e14bf8ae59

+ 2 - 1
.kiro/specs/reduce-modules-loaded/analysis-ledger.md

@@ -23,7 +23,8 @@ Measured via `ChunkModuleStatsPlugin` in `next.config.utils.js`. The `initial` c
 | Step | Task | initial | async-only | total | Compiled modules | Date |
 | Step | Task | initial | async-only | total | Compiled modules | Date |
 |------|------|---------|------------|-------|------------------|------|
 |------|------|---------|------------|-------|------------------|------|
 | **Baseline (no Phase 2 changes)** | 8.1 | **2,704** | 4,146 | 6,850 | 10,068 | 2026-02-20 |
 | **Baseline (no Phase 2 changes)** | 8.1 | **2,704** | 4,146 | 6,850 | 10,068 | 2026-02-20 |
-| + MermaidViewer dynamic + date-fns subpath | 8.1 | **2,128** | 4,717 | 6,845 | 10,058 | 2026-02-20 |
+| + MermaidViewer dynamic + date-fns subpath | 8.3 | **2,128** | 4,717 | 6,845 | 10,058 | 2026-02-20 |
+| + date-fns locale subpath imports | 8.N | **1,630** | 4,717 | 6,347 | 9,062 | 2026-02-20 |
 
 
 > **Note**: Originally reported baseline was 51.5s, but automated measurement on the same machine consistently shows ~31s. The 51.5s figure may reflect cold cache, different system load, or an earlier codebase state.
 > **Note**: Originally reported baseline was 51.5s, but automated measurement on the same machine consistently shows ~31s. The 51.5s figure may reflect cold cache, different system load, or an earlier codebase state.
 
 

+ 8 - 0
.kiro/specs/reduce-modules-loaded/tasks.md

@@ -173,6 +173,14 @@ The following loop repeats until the user declares completion:
   - Result: initial: 2,128 (-576, -21.3%) / async-only: 4,717 / total: 6,845
   - Result: initial: 2,128 (-576, -21.3%) / async-only: 4,717 / total: 6,845
   - _Requirements: 7.2, 4.1, 6.1_
   - _Requirements: 7.2, 4.1, 6.1_
 
 
+- [x] 8.4 Loop iteration 2: date-fns locale barrel → individual subpath imports
+  - Converted `locale-utils.ts` import from `date-fns/locale` barrel (96 locales × 6 modules = ~576 modules) to individual subpath imports (`date-fns/locale/en-US`, `/fr`, `/ja`, `/ko`, `/zh-CN`)
+  - Updated `locale-utils.spec.ts` import paths to match
+  - Enhanced `ChunkModuleStatsPlugin` with `DUMP_INITIAL_MODULES=1` diagnostic mode for per-package breakdown
+  - Result: initial: 1,630 (-498, -23.4%) / async-only: 4,717 / total: 6,347 / compiled: 9,062
+  - date-fns: 560 → 62 modules in initial chunks
+  - _Requirements: 4.1, 6.1_
+
 - [ ] 8.N Loop iteration N: (next iteration — measure, analyze, propose, implement)
 - [ ] 8.N Loop iteration N: (next iteration — measure, analyze, propose, implement)
 
 
 ## Phase 3: Next.js Version Upgrade Evaluation (Deferred)
 ## Phase 3: Next.js Version Upgrade Evaluation (Deferred)

+ 5 - 1
apps/app/src/utils/locale-utils.spec.ts

@@ -1,4 +1,8 @@
-import { enUS, fr, ja, ko, zhCN } from 'date-fns/locale';
+import { enUS } from 'date-fns/locale/en-US';
+import { fr } from 'date-fns/locale/fr';
+import { ja } from 'date-fns/locale/ja';
+import { ko } from 'date-fns/locale/ko';
+import { zhCN } from 'date-fns/locale/zh-CN';
 import { describe, expect, it } from 'vitest';
 import { describe, expect, it } from 'vitest';
 
 
 import { getLocale } from './locale-utils';
 import { getLocale } from './locale-utils';

+ 6 - 1
apps/app/src/utils/locale-utils.ts

@@ -1,4 +1,9 @@
-import { enUS, fr, ja, ko, type Locale, zhCN } from 'date-fns/locale';
+import type { Locale } from 'date-fns/locale';
+import { enUS } from 'date-fns/locale/en-US';
+import { fr } from 'date-fns/locale/fr';
+import { ja } from 'date-fns/locale/ja';
+import { ko } from 'date-fns/locale/ko';
+import { zhCN } from 'date-fns/locale/zh-CN';
 
 
 const DATE_FNS_LOCALE_MAP: Record<string, Locale | undefined> = {
 const DATE_FNS_LOCALE_MAP: Record<string, Locale | undefined> = {
   en: enUS,
   en: enUS,