forked from neanes/neanes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.mjs
171 lines (164 loc) · 5.29 KB
/
vite.config.mjs
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
import { createRequire } from 'node:module';
const require = createRequire(import.meta.url);
import { rmSync } from 'node:fs';
import vue from '@vitejs/plugin-vue';
import path from 'path';
import { defineConfig, loadEnv } from 'vite';
import electron from 'vite-plugin-electron';
import eslintPlugin from 'vite-plugin-eslint';
import { VitePWA } from 'vite-plugin-pwa';
import VueDevTools from 'vite-plugin-vue-devtools';
import pkg from './package.json';
// https://vitejs.dev/config/
export default defineConfig(({ command, mode }) => {
rmSync('dist-electron', { recursive: true, force: true });
const isServe = command === 'serve';
const isBuild = command === 'build';
const sourcemap = isServe || !!process.env.VSCODE_DEBUG;
process.env = { ...process.env, ...loadEnv(mode, process.cwd()) };
return {
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
},
},
define: {
APP_VERSION: JSON.stringify(process.env.npm_package_version),
},
plugins: [
mode === 'web'
? VitePWA({
registerType: null, // We'll inject the service worker ourselves
includeAssets: [
'favicon-32.png',
'favicon-16.png',
'apple-touch-icon.png',
'msapplication-icon.png',
'safari-pinned-tab.svg',
],
manifest: {
name: 'Neanes',
short_name: 'Neanes',
description: 'A Byzantine Chant Scorewriter',
theme_color: '#052F43',
icons: [
{
src: 'assets/icons/icon-72x72.png',
sizes: '72x72',
type: 'image/png',
purpose: 'maskable any',
},
{
src: 'assets/icons/icon-96x96.png',
sizes: '96x96',
type: 'image/png',
purpose: 'maskable any',
},
{
src: 'assets/icons/icon-128x128.png',
sizes: '128x128',
type: 'image/png',
purpose: 'maskable any',
},
{
src: 'assets/icons/icon-144x144.png',
sizes: '144x144',
type: 'image/png',
purpose: 'maskable any',
},
{
src: 'assets/icons/icon-152x152.png',
sizes: '152x152',
type: 'image/png',
purpose: 'maskable any',
},
{
src: 'assets/icons/icon-192x192.png',
sizes: '192x192',
type: 'image/png',
purpose: 'maskable any',
},
{
src: 'assets/icons/icon-384x384.png',
sizes: '384x384',
type: 'image/png',
purpose: 'maskable any',
},
{
src: 'assets/icons/icon-512x512.png',
sizes: '512x512',
type: 'image/png',
purpose: 'maskable any',
},
],
},
})
: undefined,
vue(),
process.env.VITE_ENABLE_DEV_TOOLS === 'true' ? VueDevTools() : undefined,
eslintPlugin(),
!mode.includes('web')
? electron([
{
// Main-Process entry file of the Electron App.
entry: 'electron/main/index.ts',
onstart(options) {
if (process.env.VSCODE_DEBUG) {
console.log(
/* For `.vscode/.debug.script.mjs` */ '[startup] Electron App',
);
} else {
options.startup();
}
},
vite: {
build: {
sourcemap,
minify: isBuild,
outDir: 'dist-electron/main',
rollupOptions: {
external: Object.keys(
'dependencies' in pkg ? pkg.dependencies : {},
),
},
},
},
},
{
entry: 'electron/preload/index.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();
},
vite: {
build: {
sourcemap: sourcemap ? 'inline' : undefined, // #332
minify: isBuild,
outDir: 'dist-electron/preload',
rollupOptions: {
external: Object.keys(
'dependencies' in pkg ? pkg.dependencies : {},
),
},
},
},
},
])
: undefined,
],
server:
process.env.VSCODE_DEBUG &&
(() => {
const url = new URL(pkg.debug.env.VITE_DEV_SERVER_URL);
return {
host: url.hostname,
port: +url.port,
};
})(),
test: {
globals: true,
},
clearScreen: false,
};
});