-
Notifications
You must be signed in to change notification settings - Fork 10
/
vite.config.mts
163 lines (160 loc) · 5 KB
/
vite.config.mts
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
// vite.config.mts
// https://vite.dev/config/
import { URL, fileURLToPath } from "node:url";
// Utilities
import { defineConfig } from "vite";
// Vite plugins
import electron from "vite-plugin-electron";
import { VitePWA } from "vite-plugin-pwa";
import vuetify, { transformAssetUrls } from "vite-plugin-vuetify";
// import vueDevTools from "vite-plugin-vue-devtools";
// Plugins
import vue from "@vitejs/plugin-vue";
// https://vitejs.dev/config/
export default defineConfig((configEnv: { mode: string }) => ({
build: {
assetsInclude: ["**/*.nestml"],
// chunkSizeWarningLimit: 1000, // https://github.com/vitejs/vite/discussions/9440
outDir: "./nest_desktop/app",
// https://stackoverflow.com/questions/71180561/vite-change-ouput-directory-of-assets
rollupOptions: {
output: {
assetFileNames: (assetInfo: { name: string }) => {
const name = assetInfo.name;
let extType = name.split(".").at(1);
if (/png|svg/.test(extType)) {
extType = "img";
} else if (/woff|woff2|eot|ttf|otf/.test(extType)) {
extType = "fonts";
}
if (name.startsWith("vendors_")) {
return `assets/${extType}/vendors/${name.slice(8)}-[hash][extname]`;
}
return `assets/${extType}/[name]-[hash][extname]`;
},
chunkFileNames: (assetInfo: { facadeModuleId: string; name: string }) => {
// https://github.com/vitejs/vite-plugin-vue/issues/19
const name = assetInfo.name;
if (name.startsWith("vendors_")) {
return `assets/js/vendors/${name.slice(8)}-[hash].js`;
}
return `assets/js/${name}-[hash].js`;
},
entryFileNames: "assets/js/[name]-[hash].js",
manualChunks: (id: string): string => {
// https://github.com/vitejs/vite/discussions/9440#discussioncomment-10131471
const path = id.toString().split("/");
if (path.includes("node_modules")) {
const vendor = path[path.indexOf("node_modules") + 1];
return "vendors_" + (vendor.startsWith("d3") ? "@d3" : vendor);
}
return "main";
},
},
},
sourcemap: configEnv.mode === "development",
},
define: {
global: "window",
"process.env": {
APP_VERSION: process.env.npm_package_version,
},
},
plugins: [
vue({
template: { transformAssetUrls },
}),
// https://github.com/vuetifyjs/vuetify-loader/tree/next/packages/vite-plugin
vuetify({
autoImport: true,
}),
VitePWA({
devOptions: {
enabled: true,
type: "module",
},
includeAssets: [
"favicon.ico",
"apple-touch-icon-180x180.png",
"maskable-icon-512x512.png",
"pwa-64x64.png",
"pwa-192x192.png",
"pwa-512x512.png",
],
manifest: {
name: "NEST Desktop",
short_name: "NEST Desktop",
description: "A web-based application which provides a graphical user interface for NEST Simulator",
theme_color: "#ffffff",
start_url: "/",
icons: [
{
src: "pwa-64x64.png",
sizes: "64x64",
type: "image/png",
},
{
src: "pwa-192x192.png",
sizes: "192x192",
type: "image/png",
},
{
src: "pwa-512x512.png",
sizes: "512x512",
type: "image/png",
purpose: "any",
},
{
src: "maskable-icon-512x512.png",
sizes: "512x512",
type: "image/png",
purpose: "maskable",
},
],
},
registerType: "autoUpdate",
workbox: {
globPatterns: ["**/*.{eot,woff,tff,woff2,js,css,ico,png,svg}"],
// maximumFileSizeToCacheInBytes: 2000000,
// Don't fallback on document based (e.g. `/some-page`) requests
// Even though this says `null` by default, I had to set this specifically to `null` to make it work
navigateFallback: null,
},
}),
// vueDevTools(),
electron([
{
entry: "electron/main.ts",
onstart(options) {
// Start Electron App
if (JSON.parse(process.env["VITE_DEV_ELECTRON_STARTUP"] || "false")) {
options.startup([".", "--no-sandbox"]);
}
},
},
{
entry: "electron/preload.ts",
onstart(options) {
// Notify the Renderer-Process to reload the page when the Preload-Scripts build is complete,
// instead of restarting the entire Electron App.
options.reload();
},
},
]),
],
resolve: {
alias: {
"@": fileURLToPath(new URL("./src", import.meta.url)),
},
extensions: [".js", ".json", ".jsx", ".mjs", ".mustache", ".ts", ".tsx", ".vue"],
},
server: {
port: 54286,
warmup: {
clientFiles: ["./src/views/*.vue", "./src/simulators/*/views/*.vue"],
},
watch: {
ignored: ["**/coverage/**", "**/release/**"],
},
},
}));