From 935808f5ea12e263e4d220e5cd4d3ff34acb3a08 Mon Sep 17 00:00:00 2001 From: Shirasawa <764798966@qq.com> Date: Tue, 30 Dec 2025 21:51:50 +0800 Subject: [PATCH] feat: Dynamically load mammoth to speed up page loading (#20202) --- src/lib/utils/index.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/lib/utils/index.ts b/src/lib/utils/index.ts index 5343a30552..16d2fd1079 100644 --- a/src/lib/utils/index.ts +++ b/src/lib/utils/index.ts @@ -15,7 +15,6 @@ dayjs.extend(localizedFormat); import { TTS_RESPONSE_SPLIT } from '$lib/types'; -import mammoth from 'mammoth'; import pdfWorkerUrl from 'pdfjs-dist/build/pdf.worker.mjs?url'; import { marked } from 'marked'; @@ -1521,7 +1520,10 @@ export const extractContentFromFile = async (file: File) => { } async function extractDocxText(file: File) { - const arrayBuffer = await file.arrayBuffer(); + const [arrayBuffer, { default: mammoth }] = await Promise.all([ + file.arrayBuffer(), + import('mammoth') + ]); const result = await mammoth.extractRawText({ arrayBuffer }); return result.value; // plain text }