MCPcopy
hub / github.com/lowdefy/lowdefy / patchNextConfig

Function patchNextConfig

scripts/lib/patchNextConfig.mjs:28–50  ·  view source on GitHub ↗
({ targetDir })

Source from the content-addressed store, hash-verified

26// Turbopack's resolveAlias does not handle absolute paths (it prepends "./"),
27// so we resolve paths relative to __dirname at runtime in next.config.js.
28function patchNextConfig({ targetDir }) {
29 const nextConfigPath = path.join(targetDir, 'next.config.js');
30 let content = fs.readFileSync(nextConfigPath, 'utf8');
31
32 // Silence the "multiple lockfiles" warning by telling Next.js the
33 // monorepo root is the output file tracing root.
34 if (content.includes('turbopack: {},')) {
35 content = content.replace(
36 'turbopack: {},',
37 [
38 `outputFileTracingRoot: require('path').resolve(__dirname, '../..'),`,
39 ` turbopack: {`,
40 ` resolveAlias: {`,
41 ` react: './' + require('path').relative(__dirname, require('path').dirname(require.resolve('react/package.json'))),`,
42 ` 'react-dom': './' + require('path').relative(__dirname, require('path').dirname(require.resolve('react-dom/package.json'))),`,
43 ` },`,
44 ` },`,
45 ].join('\n')
46 );
47 }
48
49 fs.writeFileSync(nextConfigPath, content);
50}
51
52export default patchNextConfig;

Callers 2

dev.mjsFile · 0.85
build.mjsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected