-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
157 lines (154 loc) · 3.4 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
import vue from "@vitejs/plugin-vue";
import vueJsx from "@vitejs/plugin-vue-jsx";
import autoprefixer from "autoprefixer";
import { URL, fileURLToPath } from "node:url";
import { visualizer } from "rollup-plugin-visualizer";
import tailwind from "tailwindcss";
import type { ConfigEnv, PluginOption, UserConfig } from "vite";
import { defineConfig } from "vite";
import Compression from "vite-plugin-compression";
import { createHtmlPlugin } from "vite-plugin-html";
import Inspect from "vite-plugin-inspect";
import { VitePWA } from "vite-plugin-pwa";
import VueDevTools from "vite-plugin-vue-devtools";
import svgLoader from "vite-svg-loader";
import { siteConfig } from "./src/config/site-config";
const postcssImport = (await import("postcss-import")).default;
const postcssNesting = (await import("postcss-nesting")).default;
export default defineConfig(({ mode }: ConfigEnv): UserConfig => {
const plugins: PluginOption[] = [
vue(),
vueJsx(),
VueDevTools(),
Inspect(),
svgLoader(),
Compression({
algorithm: "gzip",
ext: ".gz",
}),
VitePWA({
registerType: "autoUpdate",
includeAssets: [
"favicon.ico",
"apple-touch-icon.png",
"masked-icon.svg",
],
devOptions: {
enabled: true,
},
manifest: {
name: siteConfig.name,
short_name: siteConfig.name,
description: siteConfig.description,
theme_color: siteConfig.themeColor,
icons: [
{
src: siteConfig.manifest.icons.androidChrome.small,
sizes: "192x192",
type: "image/png",
},
{
src: siteConfig.manifest.icons.androidChrome.large,
sizes: "512x512",
type: "image/png",
},
{
src: siteConfig.manifest.icons.androidChrome.large,
sizes: "512x512",
type: "image/png",
purpose: "any maskable",
},
],
},
workbox: {
cleanupOutdatedCaches: true,
globDirectory: "dist", // Change this to "dist"
globPatterns: ["**/*.{js,css,html,ico,png,svg,woff2}"],
globIgnores: ["**/node_modules/**/*", "sw.js", "workbox-*.js"],
},
}),
createHtmlPlugin({
inject: {
data: {
siteConfig, // Spread the entire siteConfig object
// test: 'Hello, World!',
},
tags: [
{
injectTo: "head",
tag: "meta",
attrs: {
name: "theme-color",
content: siteConfig.themeColor,
},
},
],
},
minify: true,
template: "index.html",
}),
];
if (mode === "analyze") {
plugins.push(
visualizer({
open: true,
filename: "dist/stats.html",
gzipSize: true,
brotliSize: true,
}) as PluginOption,
);
}
return {
define: {
// Inject siteConfig into the app
"import.meta.env.SITE_CONFIG": JSON.stringify(siteConfig),
},
server: {
port: 3000,
open: true,
cors: true,
},
css: {
devSourcemap: true,
postcss: {
plugins: [
postcssImport,
postcssNesting,
tailwind(),
autoprefixer(),
],
},
},
plugins,
resolve: {
alias: {
"@": fileURLToPath(new URL("./src", import.meta.url)),
},
},
build: {
sourcemap: false,
rollupOptions: {
output: {
manualChunks: {
vue: ["vue", "vue-router", "pinia"],
vendors: ["@vueuse/core"],
},
},
},
minify: "terser",
terserOptions: {
compress: {
drop_console: true,
drop_debugger: true,
},
},
},
optimizeDeps: {
include: ["web-vitals"],
},
preview: {
port: 4173,
open: true,
},
};
});