feat: Dynamically load mammoth to speed up page loading (#20202)

This commit is contained in:
Shirasawa 2025-12-30 21:51:50 +08:00 committed by GitHub
parent 464846d4a3
commit 935808f5ea
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -15,7 +15,6 @@ dayjs.extend(localizedFormat);
import { TTS_RESPONSE_SPLIT } from '$lib/types'; import { TTS_RESPONSE_SPLIT } from '$lib/types';
import mammoth from 'mammoth';
import pdfWorkerUrl from 'pdfjs-dist/build/pdf.worker.mjs?url'; import pdfWorkerUrl from 'pdfjs-dist/build/pdf.worker.mjs?url';
import { marked } from 'marked'; import { marked } from 'marked';
@ -1521,7 +1520,10 @@ export const extractContentFromFile = async (file: File) => {
} }
async function extractDocxText(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 }); const result = await mammoth.extractRawText({ arrayBuffer });
return result.value; // plain text return result.value; // plain text
} }