chore(web): refactor next.config.js to next.config.ts (#31331)

This commit is contained in:
Bowen Liang
2026-01-21 15:07:32 +08:00
committed by GitHub
parent 4b068022e1
commit d4f5a113ed
+4 -4
View File
@@ -1,3 +1,4 @@
import type { NextConfig } from 'next'
import process from 'node:process' import process from 'node:process'
import withBundleAnalyzerInit from '@next/bundle-analyzer' import withBundleAnalyzerInit from '@next/bundle-analyzer'
import createMDX from '@next/mdx' import createMDX from '@next/mdx'
@@ -24,10 +25,9 @@ const withBundleAnalyzer = withBundleAnalyzerInit({
const hasSetWebPrefix = process.env.NEXT_PUBLIC_WEB_PREFIX const hasSetWebPrefix = process.env.NEXT_PUBLIC_WEB_PREFIX
const port = process.env.PORT || 3000 const port = process.env.PORT || 3000
const locImageURLs = !hasSetWebPrefix ? [new URL(`http://localhost:${port}/**`), new URL(`http://127.0.0.1:${port}/**`)] : [] const locImageURLs = !hasSetWebPrefix ? [new URL(`http://localhost:${port}/**`), new URL(`http://127.0.0.1:${port}/**`)] : []
const remoteImageURLs = [hasSetWebPrefix ? new URL(`${process.env.NEXT_PUBLIC_WEB_PREFIX}/**`) : '', ...locImageURLs].filter(item => !!item) const remoteImageURLs = ([hasSetWebPrefix ? new URL(`${process.env.NEXT_PUBLIC_WEB_PREFIX}/**`) : '', ...locImageURLs].filter(item => !!item)) as URL[]
/** @type {import('next').NextConfig} */ const nextConfig: NextConfig = {
const nextConfig = {
basePath: process.env.NEXT_PUBLIC_BASE_PATH || '', basePath: process.env.NEXT_PUBLIC_BASE_PATH || '',
serverExternalPackages: ['esbuild-wasm'], serverExternalPackages: ['esbuild-wasm'],
transpilePackages: ['echarts', 'zrender'], transpilePackages: ['echarts', 'zrender'],
@@ -42,7 +42,7 @@ const nextConfig = {
// https://nextjs.org/docs/messages/next-image-unconfigured-host // https://nextjs.org/docs/messages/next-image-unconfigured-host
images: { images: {
remotePatterns: remoteImageURLs.map(remoteImageURL => ({ remotePatterns: remoteImageURLs.map(remoteImageURL => ({
protocol: remoteImageURL.protocol.replace(':', ''), protocol: remoteImageURL.protocol.replace(':', '') as 'http' | 'https',
hostname: remoteImageURL.hostname, hostname: remoteImageURL.hostname,
port: remoteImageURL.port, port: remoteImageURL.port,
pathname: remoteImageURL.pathname, pathname: remoteImageURL.pathname,