79 lines
2.2 KiB
TypeScript

import { existsSync } from 'node:fs'
import { createRequire } from 'node:module'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import type { NextConfig } from 'next'
const configuredBasePath = process.env.NEXT_PUBLIC_PASCAL_BASE_PATH?.trim() ?? ''
const basePath = configuredBasePath ? `/${configuredBasePath.replace(/^\/+|\/+$/g, '')}` : undefined
const pascalRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../..')
const resolveFromEditor = createRequire(import.meta.url).resolve
function workspaceModule(name: string) {
let directory = path.dirname(resolveFromEditor(name))
while (directory !== path.dirname(directory)) {
if (existsSync(path.join(directory, 'package.json'))) return directory
directory = path.dirname(directory)
}
throw new Error(`Could not resolve package root for ${name}`)
}
const nextConfig: NextConfig = {
basePath,
distDir: process.env.PASCAL_NEXT_DIST_DIR?.trim() || '.next',
logging: {
browserToTerminal: true,
},
typescript: {
ignoreBuildErrors: true,
},
transpilePackages: [
'three',
'@pascal-app/viewer',
'@pascal-app/core',
'@pascal-app/editor',
'@pascal-app/mcp',
'@pascal-app/plugin-trees',
'@dgreenheck/ez-tree',
],
turbopack: {
root: pascalRoot,
resolveAlias: {
react: './node_modules/react',
three: './node_modules/three',
'@react-three/fiber': './node_modules/@react-three/fiber',
'@react-three/drei': './node_modules/@react-three/drei',
},
},
webpack: (config) => {
config.resolve.alias = {
...config.resolve.alias,
'react$': workspaceModule('react'),
'three$': workspaceModule('three'),
'@react-three/fiber$': workspaceModule('@react-three/fiber'),
'@react-three/drei$': workspaceModule('@react-three/drei'),
}
return config
},
experimental: {
serverActions: {
bodySizeLimit: '100mb',
},
},
images: {
unoptimized: process.env.NEXT_PUBLIC_ASSETS_CDN_URL?.startsWith('http://localhost') ?? false,
remotePatterns: [
{
protocol: 'https',
hostname: '**',
},
{
protocol: 'http',
hostname: '**',
},
],
},
}
export default nextConfig