File size: 797 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import {
  NodeModuleTracePlugin,
  NodeModuleTracePluginOptions,
} from '@vercel/webpack-nft'
import type { NextConfig } from 'next'

export function createNodeFileTrace(options?: NodeModuleTracePluginOptions) {
  return function withNodeFileTrace(config: NextConfig = {}) {
    const createWebpackConfig = config.webpack
    config.outputFileTracing = false
    config.webpack = (webpackConfig, context) => {
      const config =
        createWebpackConfig?.(webpackConfig, context) ?? webpackConfig
      if (context.isServer && !context.dev) {
        const plugin = new NodeModuleTracePlugin(options)
        if (config.plugins) {
          config.plugins.push(plugin)
        } else {
          config.plugins = [plugin]
        }
      }

      return config
    }
    return config
  }
}