|
1 | 1 | import type { NextConfig } from "next"; |
2 | 2 |
|
| 3 | +const isAnalyzeEnabled = process.env.ANALYZE === "true"; |
| 4 | + |
3 | 5 | const nextConfig: NextConfig = { |
4 | | - /* config options here */ |
| 6 | + experimental: { |
| 7 | + optimizePackageImports: [ |
| 8 | + "lucide-react", |
| 9 | + "recharts", |
| 10 | + "framer-motion", |
| 11 | + "wagmi", |
| 12 | + "viem", |
| 13 | + ], |
| 14 | + }, |
| 15 | + images: { |
| 16 | + remotePatterns: [ |
| 17 | + { |
| 18 | + protocol: "https", |
| 19 | + hostname: "images.unsplash.com", |
| 20 | + }, |
| 21 | + ], |
| 22 | + formats: ["image/avif", "image/webp"], |
| 23 | + }, |
| 24 | + async headers() { |
| 25 | + return [ |
| 26 | + { |
| 27 | + source: "/_next/static/:path*", |
| 28 | + headers: [ |
| 29 | + { |
| 30 | + key: "Cache-Control", |
| 31 | + value: "public, max-age=31536000, immutable", |
| 32 | + }, |
| 33 | + ], |
| 34 | + }, |
| 35 | + { |
| 36 | + source: "/:path*.(png|jpg|jpeg|gif|webp|avif|svg|ico)", |
| 37 | + headers: [ |
| 38 | + { |
| 39 | + key: "Cache-Control", |
| 40 | + value: "public, max-age=604800, stale-while-revalidate=86400", |
| 41 | + }, |
| 42 | + ], |
| 43 | + }, |
| 44 | + { |
| 45 | + source: "/sw.js", |
| 46 | + headers: [ |
| 47 | + { |
| 48 | + key: "Cache-Control", |
| 49 | + value: "no-cache, no-store, must-revalidate", |
| 50 | + }, |
| 51 | + ], |
| 52 | + }, |
| 53 | + ]; |
| 54 | + }, |
| 55 | + webpack: (config, { isServer, webpack }) => { |
| 56 | + config.resolve = config.resolve ?? {}; |
| 57 | + config.resolve.alias = { |
| 58 | + ...(config.resolve.alias ?? {}), |
| 59 | + "@walletconnect/ethereum-provider": false, |
| 60 | + "@safe-global/safe-apps-sdk": false, |
| 61 | + "@safe-global/safe-apps-provider": false, |
| 62 | + "@base-org/account": false, |
| 63 | + "@gemini-wallet/core": false, |
| 64 | + "@react-native-async-storage/async-storage": false, |
| 65 | + porto: false, |
| 66 | + "porto/internal": false, |
| 67 | + }; |
| 68 | + |
| 69 | + if (!isServer && config.optimization?.splitChunks) { |
| 70 | + config.optimization.splitChunks = { |
| 71 | + ...config.optimization.splitChunks, |
| 72 | + cacheGroups: { |
| 73 | + ...(config.optimization.splitChunks.cacheGroups ?? {}), |
| 74 | + web3: { |
| 75 | + name: "web3-vendors", |
| 76 | + test: /[\\/]node_modules[\\/](wagmi|viem|ethers|@walletconnect|@metamask|@coinbase)[\\/]/, |
| 77 | + chunks: "all", |
| 78 | + priority: 35, |
| 79 | + }, |
| 80 | + charts: { |
| 81 | + name: "chart-vendors", |
| 82 | + test: /[\\/]node_modules[\\/](recharts|d3-.*)[\\/]/, |
| 83 | + chunks: "all", |
| 84 | + priority: 25, |
| 85 | + }, |
| 86 | + }, |
| 87 | + }; |
| 88 | + } |
| 89 | + |
| 90 | + if (isAnalyzeEnabled && !isServer) { |
| 91 | + class BuildStatsPlugin { |
| 92 | + apply(compiler: any) { |
| 93 | + compiler.hooks.done.tap("BuildStatsPlugin", (stats: any) => { |
| 94 | + const fs = require("fs"); |
| 95 | + const path = require("path"); |
| 96 | + const outputPath = path.join(compiler.options.output.path ?? ".next", "build-stats.json"); |
| 97 | + fs.writeFileSync( |
| 98 | + outputPath, |
| 99 | + JSON.stringify( |
| 100 | + stats.toJson({ |
| 101 | + all: false, |
| 102 | + assets: true, |
| 103 | + chunks: true, |
| 104 | + chunkGroups: true, |
| 105 | + }), |
| 106 | + null, |
| 107 | + 2 |
| 108 | + ) |
| 109 | + ); |
| 110 | + }); |
| 111 | + } |
| 112 | + } |
| 113 | + |
| 114 | + config.plugins.push(new BuildStatsPlugin()); |
| 115 | + } |
| 116 | + |
| 117 | + return config; |
| 118 | + }, |
5 | 119 | }; |
6 | 120 |
|
7 | 121 | export default nextConfig; |
0 commit comments