-
Notifications
You must be signed in to change notification settings - Fork 119
Expand file tree
/
Copy pathvite.config.js
More file actions
143 lines (136 loc) · 3.57 KB
/
Copy pathvite.config.js
File metadata and controls
143 lines (136 loc) · 3.57 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
import path from "node:path"
import { fileURLToPath } from "node:url"
import babel from "@rolldown/plugin-babel"
import react, { reactCompilerPreset } from "@vitejs/plugin-react"
import { visualizer } from "rollup-plugin-visualizer"
import { defineConfig, loadEnv } from "vite"
import { VitePWA } from "vite-plugin-pwa"
const { dirname, resolve } = path
const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)
const BASE_PATH_PATTERN = /^\/(?:[A-Za-z0-9._~-]+\/)*$/
const getBasePath = (value) => {
const basePath = value?.trim() || "/"
const segments = basePath.split("/").filter(Boolean)
if (
!BASE_PATH_PATTERN.test(basePath) ||
segments.some((segment) => segment === "." || segment === "..")
) {
throw new Error(
'VITE_BASE_PATH must be "/" or an absolute path that starts and ends with "/" (for example, "/reactflux/"). Path segments may contain only letters, numbers, ".", "_", "~", and "-".',
)
}
return basePath
}
export default defineConfig(({ mode }) => ({
base: getBasePath(loadEnv(mode, __dirname).VITE_BASE_PATH),
plugins: [
react(),
babel({
presets: [reactCompilerPreset()],
}),
VitePWA({
registerType: "autoUpdate",
devOptions: {
enabled: false,
},
manifest: {
name: "ReactFlux",
short_name: "ReactFlux",
description: "A Simple but Powerful RSS Reader for Miniflux",
icons: [
{
src: "favicon.ico",
sizes: "64x64 32x32 24x24 16x16",
type: "image/x-icon",
},
{
src: "logo192.png",
sizes: "192x192",
type: "image/png",
},
{
src: "logo512.png",
sizes: "512x512",
type: "image/png",
},
],
theme_color: "#1F2327",
background_color: "#ffffff",
display: "fullscreen",
},
workbox: {
cleanupOutdatedCaches: true,
globPatterns: [
"**/*.html",
"styles/*.css",
"assets/index-*.{js,css}",
"assets/react-*.js",
"assets/rolldown-runtime-*.js",
"assets/warning-*.js",
"assets/workbox-window*.js",
],
runtimeCaching: [
{
urlPattern: /\/assets\/.*\.(?:css|js)$/,
handler: "CacheFirst",
options: {
cacheName: "runtime-build-assets",
expiration: {
maxAgeSeconds: 60 * 60 * 24 * 30,
maxEntries: 80,
},
},
},
{
urlPattern: /\/fonts\/.*\.woff2$/,
handler: "CacheFirst",
options: {
cacheName: "runtime-fonts",
expiration: {
maxAgeSeconds: 60 * 60 * 24 * 365,
maxEntries: 40,
},
},
},
],
skipWaiting: true,
},
}),
mode === "analyze" &&
visualizer({
brotliSize: true,
filename: "stats.html",
gzipSize: true,
}),
],
resolve: {
alias: {
"@": resolve(__dirname, "./src"),
},
},
server: {
host: "0.0.0.0",
port: 3000,
},
preview: {
host: "0.0.0.0",
port: 3000,
},
build: {
outDir: "build",
chunkSizeWarningLimit: 600,
rolldownOptions: {
output: {
codeSplitting: {
groups: [
{
name: "react",
test: /[\\/]node_modules[\\/](react|react-dom|react-router)[\\/]/,
},
],
},
},
},
},
}))