-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathnuxt.config.ts
More file actions
174 lines (164 loc) · 5.3 KB
/
Copy pathnuxt.config.ts
File metadata and controls
174 lines (164 loc) · 5.3 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
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
// https://nuxt.com/docs/api/configuration/nuxt-config
//@ts-ignore
import { resolve } from 'pathe'
import Icons from 'unplugin-icons/vite'
import Components from 'unplugin-vue-components/vite'
import IconsResolver from 'unplugin-icons/resolver'
import { execSync } from 'child_process'
import { defineNuxtConfig } from 'nuxt/config'
let latestCommitHash = ''
let latestCommitTime = ''
try {
latestCommitHash = execSync('git rev-parse --short HEAD').toString().trim()
latestCommitTime = execSync('git log -1 --format=%ci').toString().trim()
} catch (e) {
latestCommitHash = 'unknown'
latestCommitTime = 'unknown'
}
const siteOrigin = (process.env.ORIGIN || 'https://typewords.cc').replace(/\/$/, '')
function normalizeBaseURL(baseURL: string = '/') {
if (!baseURL) return '/'
let normalizedBaseURL = baseURL.trim()
if (!normalizedBaseURL.startsWith('/')) {
normalizedBaseURL = `/${normalizedBaseURL}`
}
if (!normalizedBaseURL.endsWith('/')) {
normalizedBaseURL = `${normalizedBaseURL}/`
}
return normalizedBaseURL.replace(/\/{2,}/g, '/')
}
function withBaseURL(path: string, baseURL: string) {
if (!path.startsWith('/')) return path
if (baseURL === '/') return path
if (path === '/') return baseURL
return `${baseURL.slice(0, -1)}${path}`
}
function toSiteURL(path: string, baseURL: string) {
return new URL(withBaseURL(path, baseURL), siteOrigin).toString()
}
const appBaseURL = normalizeBaseURL(process.env.NUXT_APP_BASE_URL || '/')
export default defineNuxtConfig({
compatibilityDate: '2025-07-15',
devtools: { enabled: true },
app: {
baseURL: appBaseURL,
// keepalive: true,
head: {
title: 'Type Words — 免费英语单词练习 | Free English Typing Practice', // default fallback title
htmlAttrs: {
lang: 'zh-CN',
},
link: [{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }],
},
},
// ssr: false,
routeRules: {
'/words': { ssr: false },
'/articles': { ssr: false },
'/setting': { ssr: false },
'/book/nce1': { prerender: true },
'/book/nce2': { prerender: true },
'/book/nce3': { prerender: true },
'/book/nce4': { prerender: true },
},
vite: {
plugins: [
Components({
resolvers: [
IconsResolver({
prefix: 'Icon',
}),
],
}),
Icons({
autoInstall: true,
}),
],
},
// 模块
modules: ['@pinia/nuxt', '@unocss/nuxt', 'unplugin-icons/nuxt', '@vue-macros/nuxt', '@nuxtjs/i18n', '@nuxt/image'],
macros: {
betterDefine: false,
},
// i18n 配置
i18n: {
locales: [
{ code: 'en', language: 'en-US', file: 'en.json', name: 'English' },
{ code: 'zh', language: 'zh-CN', file: 'zh.json', name: '中文' },
{ code: 'es', language: 'es-ES', file: 'es.json', name: 'Español' },
{ code: 'fr', language: 'fr-FR', file: 'fr.json', name: 'Français' },
{ code: 'pt', language: 'pt-BR', file: 'pt.json', name: 'Português' },
{ code: 'de', language: 'de-DE', file: 'de.json', name: 'Deutsch' },
{ code: 'ru', language: 'ru-RU', file: 'ru.json', name: 'Русский' },
{ code: 'uk', language: 'uk-UA', file: 'uk.json', name: 'Українська' },
{ code: 'ja', language: 'ja-JP', file: 'ja.json', name: '日本語' },
{ code: 'ko', language: 'ko-KR', file: 'ko.json', name: '한국어' },
{ code: 'th', language: 'th-TH', file: 'th.json', name: 'ไทย' },
{ code: 'vi', language: 'vi-VN', file: 'vi.json', name: 'Tiếng Việt' },
{ code: 'id', language: 'id-ID', file: 'id.json', name: 'Bahasa Indonesia' },
{ code: 'tw', language: 'zh-TW', file: 'tw.json', name: '繁體中文' },
],
defaultLocale: 'zh',
// langDir:'app/i18n/',
strategy: 'no_prefix',
},
// CSS
css: ['~/assets/css/main.scss'],
// 别名配置
alias: {
'@': resolve(__dirname, 'app'),
},
// 自动导入配置
imports: {
dirs: ['app/composables/**', 'app/utils/**'],
},
// 组件自动导入目录
components: [
{ path: 'components', pathPrefix: false },
{ path: 'app/components', pathPrefix: false },
],
// 运行时配置
runtimeConfig: {
public: {
apiBase: process.env.API_BASE || 'http://localhost/',
origin: process.env.ORIGIN || 'https://typewords.cc',
host: process.env.HOST || 'typewords.cc',
passwordRsaPublicKey: process.env.VITE_PASSWORD_RSA_PUBLIC_KEY || '',
latestCommitHash: latestCommitHash + (process.env.NODE_ENV === 'production' ? '' : ' (dev)'),
latestCommitTime: latestCommitTime,
},
},
// 构建配置
build: {
transpile: ['vue-virtual-scroller', 'vxe-table'],
},
// 实验性功能
experimental: {
payloadExtraction: false, // 禁用 payload 提取,减少构建体积
},
// TypeScript 配置
typescript: {
strict: false,
typeCheck: false, // 构建时不进行类型检查,加快构建速度
tsConfig: {
compilerOptions: {
types: ['vue-macros/macros-global'],
allowImportingTsExtensions: true,
},
},
},
devServer: {
port: 5567,
},
nitro: {
prerender: {
ignore: appBaseURL === '/' ? [] : [withBaseURL('/manifest.json', appBaseURL)],
},
devProxy: {
'/baidu': {
target: 'https://api.fanyi.baidu.com/api/trans/vip/translate',
changeOrigin: true,
},
},
},
})