-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathnuxt.config.ts
More file actions
149 lines (133 loc) · 3.52 KB
/
nuxt.config.ts
File metadata and controls
149 lines (133 loc) · 3.52 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import { access, mkdir, writeFile } from "node:fs/promises";
import { basename, resolve } from "node:path";
const watchIgnored = [
"**/.git/**",
"**/.nuxt/**",
"**/.output/**",
"**/.data/**",
"**/dist/**",
"**/node_modules/**",
"**/.pnpm-store/**",
];
const nuxtPathsShimCode = `function joinURL(base, ...parts) {
let out = typeof base === 'string' && base.length > 0 ? base : '/'
for (const part of parts) {
if (part == null || part === '') continue
out = out.replace(/\\/+$/, '') + '/' + String(part).replace(/^\\/+/, '')
}
return out === '' ? '/' : out
}
export function baseURL() {
return process.env.NUXT_APP_BASE_URL || process.env.NITRO_APP_BASE_URL || '/'
}
export function buildAssetsDir() {
return process.env.NUXT_APP_BUILD_ASSETS_DIR || '/_nuxt/'
}
export function publicAssetsURL(...path) {
const publicBase = process.env.NUXT_APP_CDN_URL || baseURL()
return path.length > 0 ? joinURL(publicBase, ...path) : publicBase
}
export function buildAssetsURL(...path) {
return joinURL(publicAssetsURL(), buildAssetsDir(), ...path)
}
`;
async function ensureNuxtInternalPathsShim(rootDir: string) {
const runtimePackageDirs = [
// Dev runtime packages
resolve(rootDir, ".nuxt/dist/server/node_modules/nuxt"),
resolve(rootDir, ".nuxt/dist/server/node_modules/nuxt-site-config"),
resolve(rootDir, ".nuxt/dist/server/node_modules/_nuxt/content"),
resolve(rootDir, ".nuxt/dist/server/node_modules/_nuxtjs/mdc"),
// Build/preview runtime packages
resolve(rootDir, ".output/server/node_modules/nuxt"),
resolve(rootDir, ".output/server/node_modules/nuxt-site-config"),
resolve(rootDir, ".output/server/node_modules/_nuxt/content"),
resolve(rootDir, ".output/server/node_modules/_nuxtjs/mdc"),
];
for (const nuxtRuntimePackageDir of runtimePackageDirs) {
try {
await access(nuxtRuntimePackageDir);
} catch {
continue;
}
const shimDir = resolve(nuxtRuntimePackageDir, "dist/internal");
await mkdir(shimDir, { recursive: true });
await writeFile(
resolve(shimDir, "paths-shim.mjs"),
nuxtPathsShimCode,
"utf8",
);
await writeFile(
resolve(nuxtRuntimePackageDir, "package.json"),
`${JSON.stringify(
{
name: `${basename(nuxtRuntimePackageDir)}-ssr-shim`,
type: "module",
imports: {
"#internal/nuxt/paths": "./dist/internal/paths-shim.mjs",
},
},
null,
2,
)}\n`,
"utf8",
);
}
}
// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
devtools: { enabled: true },
extends: ["shadcn-docs-nuxt"],
compatibilityDate: "2024-09-19",
content: {
watch: false,
},
components: {
dirs: [
{
path: "./node_modules/shadcn-docs-nuxt/components",
ignore: ["ui/**", "**/*.ts"],
},
{
path: "~/components",
},
"~/components/ui",
{
path: "~/components/content",
prefix: "",
},
],
},
routeRules: {
"/": {
redirect: "/getting-started",
},
},
nitro: {
preset: "cloudflare_pages",
},
hooks: {
async "build:done"() {
await ensureNuxtInternalPathsShim(process.cwd());
},
},
watchers: {
chokidar: {
ignored: watchIgnored,
usePolling: true,
interval: 250,
},
},
vite: {
server: {
watch: {
ignored: watchIgnored,
usePolling: true,
interval: 250,
},
},
},
alias: {
"@": "/<rootDir>",
},
});