This repository has been archived by the owner on Oct 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
131 lines (122 loc) · 3.09 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
import { analyzer } from "vite-bundle-analyzer"
import { createHtmlPlugin } from "vite-plugin-html"
import { defineConfig } from "vite"
import { svelte } from "@sveltejs/vite-plugin-svelte"
import { vitePreprocess } from "@sveltejs/vite-plugin-svelte"
import { VitePWA } from "vite-plugin-pwa"
import * as fs from "node:fs"
import content from "@originjs/vite-plugin-content"
import deadFile from "vite-plugin-deadfile"
import injectHTML from "vite-plugin-html-inject"
import svg from "@poppanator/sveltekit-svg"
import topLevelAwait from "vite-plugin-top-level-await"
import TurboConsole from "unplugin-turbo-console/vite"
import requireTransform from "vite-plugin-require-transform"
import wasm from "vite-plugin-wasm"
const prod = process.env.NODE_ENV === "production"
const mode = prod ? "production" : "development"
const analyze = process.env.VITE_ANALYZE === "true"
function injectData() {
const data = {
project_name: "Wavetable synth in svelte.js",
project_description: "",
project_version: "",
project_keywords: "",
timestamp: "",
}
try {
const package_json_file = fs.readFileSync("package.json", "utf-8")
const package_json = JSON.parse(package_json_file)
const version = package_json?.version ?? null
const keywords = package_json?.keywords?.join(", ") ?? ""
const description = package_json?.description + (version ? ` v${version}` : "")
data.timestamp = new Date().toLocaleDateString("en-UK", {
hour: "2-digit",
minute: "2-digit",
})
if (keywords) data.project_keywords = keywords
if (version) data.project_version = version
if (description) data.project_description = description
} catch (err) {
console.log(err)
}
return data
}
let counter = 0
// https://vitejs.dev/config/
export default defineConfig({
mode,
resolve: {
alias: {
src: "/src",
ico: "/src/assets/icons",
pkg: "/target/wasm-bundler",
},
},
esbuild: {
drop: prod ? ["console", "debugger"] : [],
},
build: {
modulePreload: {
polyfill: false,
},
},
plugins: [
content({
yaml: {
enabled: true,
},
}),
wasm(),
topLevelAwait(),
svg(),
requireTransform(),
svelte({
preprocess: vitePreprocess(),
compilerOptions: {
customElement: true,
discloseVersion: false,
cssHash() {
return `_${(++counter).toString(36)}`
},
},
}),
VitePWA({
registerType: "autoUpdate",
}),
!prod && TurboConsole(),
analyze &&
analyzer({
analyzerMode: "static",
summary: true,
fileName: "vite_bundle_analytics",
}),
prod &&
deadFile({
root: "src",
include: ["**/*"],
exclude: [
"**/*.css",
"**/*.html",
"**/*.rs",
"**/*.svg",
"**/*.test.ts",
"app.d.ts",
"vite-env.d.ts",
],
}),
injectHTML(),
createHtmlPlugin({
minify: true,
inject: {
data: injectData(),
},
}),
],
preview: {
port: 3000,
},
server: {
port: 3000,
},
})