48 lines
1.9 KiB
TypeScript
48 lines
1.9 KiB
TypeScript
import type { NextConfig } from "next"
|
|
import createNextIntlPlugin from "next-intl/plugin"
|
|
import bundleAnalyzer from "@next/bundle-analyzer"
|
|
|
|
const withNextIntl = createNextIntlPlugin("./src/i18n/request.ts")
|
|
const withBundleAnalyzer = bundleAnalyzer({
|
|
enabled: process.env.ANALYZE === "true",
|
|
})
|
|
|
|
const nextConfig: NextConfig = {
|
|
output: "standalone",
|
|
// 服务端 Node.js 原生模块,不应被 Turbopack 打包到 server bundle。
|
|
// - mysql2: Node.js MySQL 驱动,依赖 net/tls
|
|
// - tencentcloud-sdk-nodejs: 腾讯云 SDK,体积 ~2-3 MB,仅在短信/对象存储等服务端调用
|
|
// - exceljs: Excel 生成库,体积 ~250-300 KB,仅在导出报表时使用
|
|
// - pino: 结构化日志库,依赖 node:async_hooks 与 transport worker 线程
|
|
serverExternalPackages: ["mysql2", "tencentcloud-sdk-nodejs", "exceljs", "pino"],
|
|
experimental: {
|
|
// 启用 optimizePackageImports 让 Turbopack 对 barrel 导出做精确 tree-shaking,
|
|
// 避免整个库被打入首屏 chunk。覆盖项目中最常用的重型库:
|
|
// - lucide-react: 图标库,barrel 导出 1000+ 图标
|
|
// - recharts: 图表库,barrel 导出 20+ 组件
|
|
// - @xyflow/react: ReactFlow,barrel 导出 30+ 模块
|
|
// - @tiptap/*: 富文本编辑器,多个 barrel 包
|
|
// - @radix-ui/*: 无障碍 UI 原语,barrel 导出
|
|
// - date-fns: 日期工具,barrel 导出 200+ 函数
|
|
optimizePackageImports: [
|
|
"lucide-react",
|
|
"recharts",
|
|
"@xyflow/react",
|
|
"@tiptap/react",
|
|
"@tiptap/starter-kit",
|
|
"@tiptap/extension-placeholder",
|
|
"@tiptap/extension-image",
|
|
"tiptap-markdown",
|
|
"@radix-ui/react-dialog",
|
|
"@radix-ui/react-dropdown-menu",
|
|
"@radix-ui/react-popover",
|
|
"@radix-ui/react-select",
|
|
"@radix-ui/react-tabs",
|
|
"@radix-ui/react-tooltip",
|
|
"date-fns",
|
|
],
|
|
},
|
|
}
|
|
|
|
export default withBundleAnalyzer(withNextIntl(nextConfig))
|