-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnext.config.mjs
More file actions
50 lines (42 loc) · 1.8 KB
/
Copy pathnext.config.mjs
File metadata and controls
50 lines (42 loc) · 1.8 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/**
* @type {import('next').NextConfig}
*/
import { readFileSync } from 'fs'
import { PHASE_DEVELOPMENT_SERVER } from 'next/dist/shared/lib/constants.js'
import { dirname, resolve } from 'path'
import { fileURLToPath } from 'url'
const __dirname = dirname(fileURLToPath(import.meta.url))
const pkg = JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf8'))
// Detect ADS packages linked locally via `pnpm run link` (link: protocol).
// When active, we widen the module-resolution root so the linked packages,
// which live outside this project, resolve correctly.
const hasLinkedAdsPackages = Object.entries(pkg.dependencies ?? {}).some(
([name, version]) => name.startsWith('@amsterdam/') && version.startsWith('link:'),
)
// The linked packages live in the sibling `design-system` workspace, outside this
// project's root. Point the module-resolution root at the shared parent directory so
// Turbopack (dev) follows the symlinks and resolves each package's own `workspace:*`
// dependencies from the design-system workspace.
const monorepoRoot = resolve(__dirname, '..')
// Dev only: widen Turbopack's root when linked packages live outside this project.
// For a production build/export, make sure your dependencies are unlinked (i.e. no `link:` entries) before building.
const devLinkConfig = hasLinkedAdsPackages ? { turbopack: { root: monorepoRoot } } : {}
const nextConfig = (phase) => {
if (phase === PHASE_DEVELOPMENT_SERVER) {
return {
...devLinkConfig,
env: {
basePath: '',
},
}
}
return {
basePath: `/design-system-prototypes${process.env.NEXT_PUBLIC_BASE_PATH}`,
env: {
basePath: `/design-system-prototypes${process.env.NEXT_PUBLIC_BASE_PATH}`,
},
images: { unoptimized: true },
output: 'export',
}
}
export default nextConfig