打包外部套件可以顯著提升應用程式的效能。(Bundling external packages can significantly improve the performance of your application.) 預設情況下,導入至應用程式的套件不會被打包。這可能會影響效能,或者如果外部套件未預先打包,例如從 monorepo 或 node_modules 導入,則可能無法正常運作。本頁面將引導您如何分析和設定套件打包。(By default, packages imported into your application are not bundled. This can impact performance or might not work if external packages are not pre-bundled, for example, if imported from a monorepo or node_modules. This page will guide you through how to analyze and configure package bundling.)
/** @type{import('next').NextConfig} */constnextConfig= {// Automatically bundle external packages in the Pages Router: bundlePagesRouterDependencies:true,// Opt specific packages out of bundling for both App and Pages Router: serverExternalPackages: ['package-name'],}module.exports= nextConfig