forked from RSSNext/Follow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
193 lines (180 loc) · 5.74 KB
/
vite.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
import { resolve } from "node:path"
import { fileURLToPath } from "node:url"
import legacy from "@vitejs/plugin-legacy"
import { minify as htmlMinify } from "html-minifier-terser"
import { cyan, dim, green } from "kolorist"
import type { PluginOption, ViteDevServer } from "vite"
import { defineConfig, loadEnv } from "vite"
import mkcert from "vite-plugin-mkcert"
import { viteRenderBaseConfig } from "./configs/vite.render.config"
import type { env as EnvType } from "./packages/shared/src/env"
import { createDependencyChunksPlugin } from "./plugins/vite/deps"
import { htmlInjectPlugin } from "./plugins/vite/html-inject"
import manifestPlugin from "./plugins/vite/manifest"
import { createPlatformSpecificImportPlugin } from "./plugins/vite/specific-import"
const __dirname = fileURLToPath(new URL(".", import.meta.url))
const isCI = process.env.CI === "true" || process.env.CI === "1"
const ROOT = "./apps/renderer"
const devPrint = (): PluginOption => ({
name: "dev-print",
configureServer(server: ViteDevServer) {
const _printUrls = server.printUrls
server.printUrls = () => {
_printUrls()
console.info(
` ${green("➜")} ${dim("Production debug")}: ${cyan(
"https://app.follow.is/__debug_proxy",
)}`,
)
console.info(
` ${green("➜")} ${dim("Development debug")}: ${cyan(
"https://dev.follow.is/__debug_proxy",
)}`,
)
}
},
})
export default ({ mode }) => {
const env = loadEnv(mode, process.cwd())
const typedEnv = env as typeof EnvType
return defineConfig({
...viteRenderBaseConfig,
root: ROOT,
envDir: resolve(__dirname, "."),
build: {
outDir: resolve(__dirname, "out/web"),
target: "ES2022",
sourcemap: isCI,
rollupOptions: {
input: {
main: resolve(ROOT, "/index.html"),
__debug_proxy: resolve(ROOT, "/__debug_proxy.html"),
},
},
},
server: {
port: 2233,
watch: {
ignored: ["**/dist/**", "**/out/**", "**/public/**", ".git/**"],
},
},
plugins: [
...((viteRenderBaseConfig.plugins ?? []) as any),
mode !== "development" &&
legacy({
targets: "defaults",
renderLegacyChunks: false,
modernTargets: ">0.3%, last 2 versions, Firefox ESR, not dead",
modernPolyfills: [
// https://unpkg.com/browse/[email protected]/modules/
"es.promise.with-resolvers",
],
}),
htmlInjectPlugin(typedEnv),
mkcert(),
devPrint(),
createDependencyChunksPlugin([
// React framework
["react", "react-dom"],
["react-error-boundary", "react-dom/server", "react-router-dom"],
// Data Statement
["zustand", "jotai", "use-context-selector", "immer", "dexie"],
// Remark
[
"remark-directive",
"remark-gfm",
"remark-parse",
"remark-stringify",
"remark-rehype",
"@microflash/remark-callout-directives",
"remark-gh-alerts",
],
// Rehype
[
"rehype-parse",
"rehype-sanitize",
"rehype-stringify",
"rehype-infer-description-meta",
"hast-util-to-jsx-runtime",
"hast-util-to-text",
"react-shadow",
],
["vfile", "unified"],
["lodash-es"],
["framer-motion"],
["clsx", "tailwind-merge", "class-variance-authority"],
[
"@radix-ui/react-dialog",
"@radix-ui/react-avatar",
"@radix-ui/react-checkbox",
"@radix-ui/react-context",
"@radix-ui/react-dropdown-menu",
"@radix-ui/react-hover-card",
"@radix-ui/react-label",
"@radix-ui/react-popover",
"@radix-ui/react-radio-group",
"@radix-ui/react-scroll-area",
"@radix-ui/react-select",
"@radix-ui/react-slider",
"@radix-ui/react-slot",
"@radix-ui/react-switch",
"@radix-ui/react-tabs",
"@radix-ui/react-toast",
"@radix-ui/react-tooltip",
"@headlessui/react",
],
["i18next", "i18next-browser-languagedetector", "react-i18next"],
// Data query
[
"@tanstack/react-query",
"@tanstack/react-query-persist-client",
"@tanstack/query-sync-storage-persister",
],
["tldts"],
["shiki", "@shikijs/transformers"],
["@sentry/react", "@openpanel/web"],
["zod", "react-hook-form", "@hookform/resolvers"],
["swiper"],
]),
createPlatformSpecificImportPlugin(false),
manifestPlugin(),
htmlPlugin(typedEnv),
],
define: {
...viteRenderBaseConfig.define,
ELECTRON: "false",
},
})
}
function checkBrowserSupport() {
if (!("findLastIndex" in Array.prototype) || !("structuredClone" in window)) {
window.alert(
"Follow is not compatible with your browser because your browser version is too old. You can download and use the Follow app or continue using it with the latest browser.",
)
window.location.href = "https://follow.is/download"
}
}
const htmlPlugin: (env: any) => PluginOption = () => {
return {
name: "html-transform",
enforce: "post",
transformIndexHtml(html) {
return htmlMinify(
html.replace(
"<!-- Check Browser Script Inject -->",
`<script>${checkBrowserSupport.toString()}; checkBrowserSupport()</script>`,
),
{
removeComments: true,
html5: true,
minifyJS: true,
minifyCSS: true,
removeTagWhitespace: true,
collapseWhitespace: true,
collapseBooleanAttributes: true,
collapseInlineTagWhitespace: true,
},
)
},
}
}