-
Notifications
You must be signed in to change notification settings - Fork 92
/
vite.config.js
211 lines (208 loc) · 8.31 KB
/
vite.config.js
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
/* eslint-disable import/no-extraneous-dependencies,prefer-regex-literals */
import { defineConfig, loadEnv } from "vite";
import { createVuePlugin } from "vite-plugin-vue2";
import ViteComponents, { VuetifyResolver } from "vite-plugin-components";
import visualizer from "rollup-plugin-visualizer";
import yaml from "@rollup/plugin-yaml";
import { VitePWA } from "vite-plugin-pwa";
import path from "path";
// Bypass vite stuff and just load .env into process.env
require("dotenv").config();
/**
* @param {{ mode: string, command: string }}
*/
export default ({ mode }) => {
const env = { ...process.env, ...loadEnv(mode, process.cwd()) };
const API_BASE_URL = env.API_BASE_URL ?? "https://staging.holodex.net";
const REWRITE_API_ROUTES = !!env.REWRITE_API_ROUTES;
return defineConfig({
plugins: [
yaml(),
createVuePlugin(),
ViteComponents({
customComponentResolvers: [VuetifyResolver()],
deep: false,
/**
* Vite-Components removes need to import components by deepscanning the src/components folder
* but is fairly dangerous in terms of how it figures out which to import. Since we are using
* manual import processes, we only want ViteComponents for vuetify resolution.
*/
}),
VitePWA({
includeAssets: [
"favicon.ico",
"robots.txt",
"img/icons/safari-pinned-tab.svg",
],
manifest: {
// content of manifest
display: "standalone",
theme_color: "#42a5f5",
name: "Holodex",
background_color: "#42a5f5",
scope: "/",
start_url: "/",
icons: [
{
src: "img/icons/android-chrome-192x192.png",
sizes: "192x192",
type: "image/png",
},
{
src: "img/icons/android-chrome-512x512.png",
sizes: "512x512",
type: "image/png",
},
],
},
workbox: {
// NOTE: `vite-plugin-pwa` expects the service worker to be called `sw.js` for some reason.
// there is no way to change this.
swDest: "./dist/sw.js",
navigateFallbackDenylist: [
/^\/api/,
/^\/assets/,
/^\/img/,
/^\/sitemap-.*/,
/^\/statics.*/,
/^.*\.js(\.map)?/,
/^.*\.css/,
/^.*\.webmanifest/,
],
runtimeCaching: [
{
urlPattern: new RegExp(
"https://fonts.(?:googleapis|gstatic).com/(.*)",
),
handler: "CacheFirst",
options: {
cacheName: "google-fonts",
expiration: {
maxEntries: 30,
},
cacheableResponse: {
statuses: [0, 200],
},
},
},
{
urlPattern: new RegExp("https://yt3.ggpht.com/ytc/(.*)"),
handler: "CacheFirst",
options: {
cacheName: "channel-photo",
expiration: {
maxAgeSeconds: 86400,
purgeOnQuotaError: true,
},
cacheableResponse: {
statuses: [0, 200],
},
},
},
{
urlPattern: new RegExp("https://www.youtube.com/player_api"),
handler: "CacheFirst",
options: {
cacheName: "youtube-player",
expiration: {
maxAgeSeconds: 10800,
maxEntries: 1,
},
cacheableResponse: {
statuses: [0, 200],
},
},
},
{
urlPattern: new RegExp(`${API_BASE_URL}/(stats|orgs).json$`),
handler: "CacheFirst",
options: {
cacheName: "holodex-statics",
expiration: {
maxAgeSeconds: 10800,
},
cacheableResponse: {
statuses: [0, 200],
},
},
},
{
urlPattern: new RegExp(`${API_BASE_URL}/statics/.*$`),
handler: "CacheFirst",
options: {
cacheName: "holodex-statics-route",
expiration: {
maxAgeSeconds: 86400,
purgeOnQuotaError: true,
},
cacheableResponse: {
statuses: [0, 200],
},
},
},
],
// workbox options for generateSW
},
}),
visualizer({ gzipSize: true }),
],
resolve: {
alias: [
{
find: "@",
replacement: path.resolve(__dirname, "src"),
},
],
},
sourcemap: true,
build: {
rollupOptions: {
input: {
main: path.resolve(__dirname, "index.html"),
seo: path.resolve(__dirname, "seo.html"),
},
output: {
compact: true,
generatedCode: {
arrowFunctions: true,
constBindings: true,
objectShorthand: true,
},
// manualChunks: (id) => {
// if (id.includes("node_modules")) {
// if (id.includes("vuetify")) {
// return "vendor_vuetify";
// }
// if (id.includes("vue")) {
// return "vendor_vue";
// }
// return "vendor"; // all other package goes here
// }
// },
},
},
},
server: {
port: 8080,
proxy: {
"/api": {
target: API_BASE_URL,
changeOrigin: true,
secure: false,
ws: true,
rewrite: (url) => (REWRITE_API_ROUTES ? url.replace(/^\/api/, "") : url),
},
"^/(stats|orgs).json$": {
target: API_BASE_URL,
changeOrigin: true,
secure: false,
},
"/statics": {
target: API_BASE_URL,
changeOrigin: true,
secure: false,
},
},
},
});
};