forked from KiWi233333/JiwuChat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnuxt.config.ts
215 lines (211 loc) · 5.98 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
// 打包分包插件解决潜在循环依赖
// import { prismjsPlugin } from "vite-plugin-prismjs";
// import { pwa } from "./config/pwa";
import { appDescription, appName } from "./constants/index";
import * as packageJson from "./package.json";
import "dayjs/locale/zh-cn";
const platform = process.env.TAURI_PLATFORM;
const isMobile = !!/android|ios/.exec(platform || "");
const BASE_URL = import.meta.env.VITE_API_BASE_URL;
const isSSR = process.env.NUXT_PUBLIC_SPA;
const mode = process.env.NUXT_PUBLIC_NODE_ENV as "development" | "production" | "test";
const version = packageJson?.version;
const host = process.env.TAURI_DEV_HOST;
// 打印
console.log(`mode:${mode} api_url:${BASE_URL} SSR:${isSSR} platform: ${platform}`);
export default defineNuxtConfig({
ssr: false,
router: {
options: {
scrollBehaviorType: "smooth",
},
},
future: {
compatibilityVersion: 4,
typescriptBundlerResolution: true, // https://nuxtjs.org.cn/docs/guide/going-further/features#typescriptbundlerresolution
},
runtimeConfig: {
public: {
baseUrl: BASE_URL,
mode,
version,
isMobile,
},
},
build: {
transpile: ["popperjs/core", "resize-detector"],
analyze: {
analyzerMode: "static", // 或其他配置
reportFilename: "report.html",
},
},
// spa情况下loading状态 web端使用 "./app/spa-loading-template.html",桌面端使用 "./app/desktop-loading-template.html"
spaLoadingTemplate: "./app/spa-loading-template.html",
// 模块
modules: [
// 工具
"@vueuse/nuxt",
"@nuxtjs/color-mode",
// UI
"@element-plus/nuxt",
"@formkit/auto-animate/nuxt",
"@unocss/nuxt", // 基础
"@pinia/nuxt", // 状态管理
"pinia-plugin-persistedstate/nuxt",
"@nuxt/eslint",
],
srcDir: "",
rootDir: "",
app: {
// pageTransition: { name: "page", mode: "out-in" },
// layoutTransition: { name: "layout", mode: "out-in" },
head: {
title: `${appName}✨`,
viewport: "width=device-width,initial-scale=1",
// 网站头部信息
link: [
{ rel: "icon", href: "/logo.png", sizes: "any" },
{ rel: "apple-touch-icon", href: "/logo.png" },
],
// 网站meta
meta: [
{ name: "viewport", content: "width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" },
{ name: "description", content: appDescription },
{ name: "apple-mobile-web-app-status-bar-style", content: "black-translucent" },
],
},
},
// https://blog.csdn.net/weixin_42553583/article/details/131372309
experimental: {
// https://nuxt.com.cn/docs/guide/going-further/experimental-features#inlinerouterules
inlineRouteRules: true,
payloadExtraction: false,
renderJsonPayloads: true, //
emitRouteChunkError: false, // https://nuxt.com.cn/docs/getting-started/error-handling#js-chunk-%E9%94%99%E8%AF%AF
// viewTransition: true, // 支持View Transition API Chorme111 https://blog.csdn.net/weixin_42553583/article/details/130474259
crossOriginPrefetch: true, // 使用 Speculation Rules API 启用跨源预取。
watcher: "parcel", // 使用 Parcel 作为文件监视器。
treeshakeClientOnly: true, // 仅客户端打包时启用 treeshaking。
noVueServer: true, // 禁用 Vue Server Renderer。
},
routeRules: {
"/": { prerender: true },
"/login": { prerender: true },
},
// 自动导入
imports: {
dirs: [
// Scan top-level modules
"composables/**",
"types/**",
],
},
// css
css: [
"@/assets/styles/init.scss",
"@/assets/styles/index.scss",
"@/assets/styles/animate.scss",
],
// alias: {
// "~": "/<srcDir>",
// "@": "/<srcDir>",
// "~~": "/<rootDir>",
// "@@": "/<rootDir>",
// "assets": "/<srcDir>/assets",
// "public": "/<srcDir>/public",
// },
colorMode: {
classSuffix: "",
},
// 3、elementPlus
elementPlus: {
icon: "ElIcon",
importStyle: "scss",
themes: ["dark"],
defaultLocale: "zh-cn",
},
// pwa
// pwa,
devServer: { host: host || "localhost" },
// nuxt开发者工具
devtools: {
enabled: false,
},
// hooks: {
// "vite:extend": function ({ config }) {
// if (config.server && config.server.hmr && config.server.hmr !== true) {
// config.server.hmr.protocol = "ws";
// config.server.hmr.host = "192.168.31.14";
// config.server.hmr.port = 3000;
// }
// },
// },
// vite
vite: {
// 为 Tauri 命令输出提供更好的支持
clearScreen: false,
// 启用环境变量 其他环境变量可以在如下网页中获知:https://v2.tauri.app/reference/environment-variables/
envPrefix: ["VITE_", "TAURI_"],
server: {
// Tauri需要一个确定的端口
strictPort: true,
hmr: host
? {
protocol: "ws",
host,
port: 1421,
}
: undefined,
// hmr: {
// host: "192.168.31.14",
// port: 3000,
// protocol: "ws",
// }, // 热更新
// watch: {
// ignored: [
// "**/src-tauri/**",
// "**/node_modules/**",
// "**/dist/**",
// "**/.git/**",
// "**/.nuxt/**",
// "**/public/**",
// "**/.output/**",
// ],
// },
},
css: {
preprocessorOptions: {
scss: {
silenceDeprecations: ["legacy-js-api"],
additionalData: `
@use "@/assets/styles/element/index.scss" as element;
@use "@/assets/styles/element/dark.scss" as dark;
@use "@/assets/styles/var.scss" as *;
`,
},
},
},
build: {
chunkSizeWarningLimit: 1000,
rollupOptions: {
output: {
manualChunks: {
},
},
// external: ["workbox-build"],
},
},
},
typescript: {
typeCheck: true,
},
eslint: {
config: {
standalone: false,
nuxt: {
sortConfigKeys: false,
},
},
},
compatibilityDate: "2024-08-14",
});