-
Notifications
You must be signed in to change notification settings - Fork 0
/
nuxt.config.ts
141 lines (128 loc) · 3.41 KB
/
nuxt.config.ts
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
import fg from "fast-glob";
import { spawnSync } from "node:child_process";
import { readFileSync } from "node:fs";
import { env } from "node:process";
import { fileURLToPath } from "node:url";
import type { NuxtConfig } from "nuxt/schema";
import * as nuxtUIConfig from "./node_modules/@nuxt/ui/dist/runtime/ui.config";
function fromProjectDir(path: string): string {
return fileURLToPath(new URL(path, import.meta.url));
}
function getAppVersion(): string {
if (env.NODE_ENV === "development" || env.NODE_ENV === "test") {
return "[dev]";
}
const pkg = JSON.parse(readFileSync(fromProjectDir("package.json"), "utf-8"));
const { stdout } = spawnSync("git", ["rev-parse", "--short", "HEAD"], {
encoding: "utf-8",
});
const pkgVersion = pkg.version;
const commitHash = stdout.trim();
return `v${pkgVersion} (${commitHash})`;
}
function getUsedIcons(ignoreCollections: string[]): string[] {
const iconSet = new Set<string>();
const files = fg.sync("app/**/*.{ts,vue}", { absolute: true });
for (const file of files) {
const content = readFileSync(file, "utf-8");
const matches = content.matchAll(/\bi-([a-z\d-]+:[a-z\d-]+)/g);
for (const match of matches) {
const name = match[1]!;
const collection = name.split(":")[0]!;
if (ignoreCollections.includes(collection)) {
continue;
}
iconSet.add(name);
}
}
const matches = JSON.stringify(nuxtUIConfig).matchAll(/"i-([a-z\d-]+)"/g);
for (const match of matches) {
const name = match[1]!.replace(/[-:]/, ":");
iconSet.add(name);
}
return Array.from(iconSet).sort();
}
const nitro =
env.NODE_ENV === "development" || env.NODE_ENV === "test"
? {}
: {
preset: "./preset",
swsr: {
fallbackBase: "loading.html",
fallbackFiles: ["index.html", "200.html", "404.html"],
},
prerender: {
autoSubfolderIndex: false,
routes: ["/about", "/signin", "/loading"],
},
};
const iconBundleOptions: NuxtConfig["icon"] =
env.NODE_ENV === "development" || env.NODE_ENV === "test"
? {
serverBundle: "local",
}
: {
serverBundle: false,
clientBundle: {
includeCustomCollections: true,
icons: getUsedIcons(["luonto"]),
},
};
// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
compatibilityDate: "2024-11-11",
future: {
compatibilityVersion: 4,
},
devtools: { enabled: true },
modules: [
"@nuxt/eslint",
// runtime related
"@hebilicious/authjs-nuxt",
"@nuxt/ui",
"@vueuse/nuxt",
"nuxt-time",
],
nitro,
authJs: {
guestRedirectTo: "/signin",
},
runtimeConfig: {
public: {
authJs: {
baseUrl: "https://service-worker",
},
appVersion: getAppVersion(),
},
},
alias: {
cookie: fromProjectDir("node_modules/cookie"),
},
ui: {
safelistColors: [
// bulk power mode toggle button
"primary",
// base colors
"black",
"gray",
"white",
// for light buttons
"orange",
"sky",
// for AC power button and bulk power mode toggle button
"emerald",
// for AC buttons: blue, sky, orange, gray
"blue",
],
},
icon: {
provider: "server",
customCollections: [
{
prefix: "luonto",
dir: "icons/build/luonto",
},
],
...iconBundleOptions,
},
});