跳到內容
配置next.config.js 選項optimizePackageImports

optimizePackageImports

有些包可以匯出數百甚至數千個模組,這可能導致開發和生產中的效能問題。

將包新增到 experimental.optimizePackageImports 將只加載你實際使用的模組,同時仍然方便你使用帶有許多命名匯出的匯入語句。

next.config.js
module.exports = {
  experimental: {
    optimizePackageImports: ['package-name'],
  },
}

以下庫預設已最佳化

  • lucide-react
  • date-fns
  • lodash-es
  • ramda
  • antd
  • react-bootstrap
  • ahooks
  • @ant-design/icons
  • @headlessui/react
  • @headlessui-float/react
  • @heroicons/react/20/solid
  • @heroicons/react/24/solid
  • @heroicons/react/24/outline
  • @visx/visx
  • @tremor/react
  • rxjs
  • @mui/material
  • @mui/icons-material
  • recharts
  • react-use
  • @material-ui/core
  • @material-ui/icons
  • @tabler/icons-react
  • mui-core
  • react-icons/*
  • effect
  • @effect/*