-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathvite.config.ts
More file actions
148 lines (146 loc) · 4.2 KB
/
vite.config.ts
File metadata and controls
148 lines (146 loc) · 4.2 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
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import tsconfigPaths from "vite-tsconfig-paths";
import monacoEditorPlugin from "vite-plugin-monaco-editor-esm";
import { nodePolyfills } from "vite-plugin-node-polyfills";
import { VitePWA } from "vite-plugin-pwa";
const ReactCompilerConfig = {};
// https://vitejs.dev/config/
export default defineConfig({
server: {
host: "0.0.0.0", // 使用 '0.0.0.0' 允许从任何 IP 访问
},
css: {
preprocessorOptions: {
scss: {
api: "modern-compiler", // or 'modern'
},
},
},
base: "./",
plugins: [
react({
babel: {
plugins: [["babel-plugin-react-compiler", ReactCompilerConfig]],
},
}),
tsconfigPaths(),
monacoEditorPlugin({
languageWorkers: ["editorWorkerService", "json", "typescript"],
}),
nodePolyfills(),
VitePWA({
registerType: "prompt", // 改为 prompt,让我们自己控制更新
strategies: "generateSW",
includeAssets: ["favicon.ico", "apple-touch-icon.png", "logo.png"],
workbox: {
maximumFileSizeToCacheInBytes: 20 * 1024 * 1024, // 20MB
globPatterns: ["**/*.{js,css,html,ico,png,svg}"],
cleanupOutdatedCaches: true, // 清理过期的缓存
skipWaiting: false, // 不自动跳过等待
clientsClaim: false, // 不自动控制所有客户端
runtimeCaching: [
{
urlPattern: /^https:\/\/fonts\.googleapis\.com\/.*/i,
handler: "CacheFirst",
options: {
cacheName: "google-fonts-cache",
expiration: {
maxEntries: 10,
maxAgeSeconds: 60 * 60 * 24 * 365, // 1 year
},
},
},
{
urlPattern: /\.(?:png|jpg|jpeg|svg|gif|webp)$/,
handler: "CacheFirst",
options: {
cacheName: "images-cache",
expiration: {
maxEntries: 100,
maxAgeSeconds: 60 * 60 * 24 * 30, // 30 days
},
},
},
{
urlPattern: /\.(?:js|css)$/,
handler: "StaleWhileRevalidate",
options: {
cacheName: "static-resources",
expiration: {
maxEntries: 50,
maxAgeSeconds: 60 * 60 * 24 * 7, // 7 days
},
},
},
],
},
devOptions: {
enabled: false, // 在开发环境中禁用 PWA
type: "module",
},
manifest: {
name: "JSON Tools - 多功能JSON处理助手",
short_name: "JSON Tools",
description: "强大的JSON工具集,支持格式化、验证、转换、编辑等多种功能",
background_color: "#ffffff",
display: "standalone",
orientation: "portrait",
scope: "/",
start_url: "/",
theme_color: "#f5f5f5",
categories: ["productivity", "developer", "utilities"],
handle_links: "auto",
icons: [
{
src: "pwa-64x64.png",
sizes: "64x64",
type: "image/png",
purpose: "any",
},
{
src: "pwa-192x192.png",
sizes: "192x192",
type: "image/png",
purpose: "any",
},
{
src: "pwa-512x512.png",
sizes: "512x512",
type: "image/png",
purpose: "any",
},
{
src: "maskable-icon-192x192.png",
sizes: "192x192",
type: "image/png",
purpose: "maskable",
},
{
src: "maskable-icon-512x512.png",
sizes: "512x512",
type: "image/png",
purpose: "maskable",
},
],
shortcuts: [
{
name: "格式化 JSON",
short_name: "格式化",
description: "快速格式化 JSON 数据",
url: "/?tool=format",
icons: [
{
src: "pwa-96x96.png",
sizes: "96x96",
},
],
},
],
},
}),
],
optimizeDeps: {
include: ["vanilla-jsoneditor-cn"],
},
});