在 Next.js
的 next.config.js
文件中开启 experimental.instrumentationHook
功能,然后在项目根目录创建 instrumentation.ts
文件,并在其中导出一个 register
函数。这个 register
函数会在 Next.js
服务启动时被执行。
js// next.config.js
const nextConfig = {
experimental: {
instrumentationHook: true,
},
}
module.exports = nextConfig
tsexport async function register() {
console.log("do something")
}
本文作者:mereith
本文链接:
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!