查看Next.js默認配置信息的幾種方法
更新時間:2025年02月21日 10:06:38 作者:南藍
文章介紹了幾種查看Next.js默認配置信息的方法,包括使用Next.js CLI、getConfigAPI、實驗性CLI命令以及在開發(fā)模式下訪問特定路徑,感興趣的小伙伴跟著小編一起來看看吧
要查看 Next.js 的默認配置信息,有幾種方法:
使用 Next.js CLI
next info
通過代碼打印配置
// next.config.js
module.exports = (phase, { defaultConfig }) => {
console.log('Default Next.js config:', defaultConfig)
return {
// your custom config
}
}
使用 getConfig API
// config.ts
import { getConfig } from 'next/config'
export default function handler(req, res) {
const nextConfig = getConfig()
res.status(200).json(nextConfig)
}
查看運行時配置
// page.tsx
import { useRouter } from 'next/router'
export default function Page() {
// 在客戶端查看運行時配置
console.log(process.env.NEXT_PUBLIC_RUNTIME_CONFIG)
return <div>...</div>
}
使用實驗性 CLI 命令(如果可用)
next inspect
// next.config.js
{
env: {},
webpack: null,
webpackDevMiddleware: null,
distDir: '.next',
assetPrefix: '',
configOrigin: 'default',
useFileSystemPublicRoutes: true,
generateBuildId: () => null,
generateEtags: true,
pageExtensions: ['tsx', 'ts', 'jsx', 'js'],
target: 'server',
poweredByHeader: true,
compress: true,
analyticsId: process.env.VERCEL_ANALYTICS_ID || '',
images: {
deviceSizes: [640, 750, 828, 1080, 1200, 1920, 2048, 3840],
imageSizes: [16, 32, 48, 64, 96, 128, 256, 384],
path: '/_next/image',
loader: 'default',
domains: [],
disableStaticImages: false,
minimumCacheTTL: 60,
formats: ['image/webp'],
},
devIndicators: {
buildActivity: true,
buildActivityPosition: 'bottom-right',
},
onDemandEntries: {
maxInactiveAge: 15 * 1000,
pagesBufferLength: 2,
},
amp: {
canonicalBase: '',
},
basePath: '',
sassOptions: {},
trailingSlash: false,
i18n: null,
productionBrowserSourceMaps: false,
optimizeFonts: true,
webpack5: undefined,
excludeDefaultMomentLocales: true,
serverRuntimeConfig: {},
publicRuntimeConfig: {},
reactStrictMode: false,
httpAgentOptions: {
keepAlive: true,
},
outputFileTracing: true,
staticPageGenerationTimeout: 60,
swcMinify: true,
output: 'standalone',
experimental: {
// 實驗性功能配置
}
}
要查看完整的運行時配置,也可以:
在開發(fā)模式下啟動項目
pnpm dev
訪問以下路徑:
http://localhost:3000/_next/config (試了無效)
到此這篇關(guān)于查看Next.js默認配置信息的幾種方法的文章就介紹到這了,更多相關(guān)查看Next.js配置信息內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
兩款JS腳本判斷手機瀏覽器類型跳轉(zhuǎn)WAP手機網(wǎng)站
本文通過兩款js腳本判斷手機瀏覽器類型跳轉(zhuǎn)到wap手機網(wǎng)站,感興趣的小伙伴快來學(xué)習(xí)吧2015-10-10
javascript 開發(fā)之百度地圖使用到的js函數(shù)整理
這篇文章主要介紹了javascript 開發(fā)之百度地圖使用到的js函數(shù)整理的相關(guān)資料,需要的朋友可以參考下2017-05-05
IScroll那些事_當內(nèi)容不足時下拉刷新的解決方法
下面小編就為大家?guī)硪黄狪Scroll那些事_當內(nèi)容不足時下拉刷新的解決方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-07-07

