-
-
Notifications
You must be signed in to change notification settings - Fork 340
Expand file tree
/
Copy pathvite.config.ts
More file actions
125 lines (122 loc) · 3.43 KB
/
vite.config.ts
File metadata and controls
125 lines (122 loc) · 3.43 KB
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
import { rmSync } from 'node:fs'
import { join, resolve } from 'node:path'
import process from 'node:process'
import Vue from '@vitejs/plugin-vue'
import dayjs from 'dayjs'
import fg from 'fast-glob'
import { SvgPackerVitePlugin } from 'svg-packer/vite'
import UnoCSS from 'unocss/vite'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { defineConfig } from 'vite'
import electron from 'vite-plugin-electron'
import renderer from 'vite-plugin-electron-renderer'
// @ts-expect-error type resolution
import esmodule from 'vite-plugin-esmodule'
import Pages from 'vite-plugin-pages'
import { VitePWA } from 'vite-plugin-pwa'
export default defineConfig(({ mode }) => {
const isElectron = mode === 'electron'
const isBuild = process.argv.slice(2).includes('build')
if (isElectron)
rmSync('dist-electron', { recursive: true, force: true })
return {
plugins: [
isElectron && electron([
{
entry: 'src/main/index.ts',
vite: {
build: {
minify: isBuild,
outDir: 'dist-electron/main',
},
},
},
]),
isElectron && renderer(),
isElectron && esmodule(['prettier']),
Vue({
customElement: [
'iconify-icon',
],
template: {
compilerOptions: {
isCustomElement: tag => tag === 'iconify-icon',
},
},
}),
Pages({
importMode: 'sync',
}),
Components({
dts: 'src/components.d.ts',
}),
AutoImport({
imports: [
'vue',
'vue-router',
'@vueuse/core',
],
dts: 'src/auto-imports.d.ts',
}),
SvgPackerVitePlugin(),
!isElectron && VitePWA({
strategies: 'injectManifest',
srcDir: 'src',
filename: 'sw.ts',
registerType: 'autoUpdate',
manifest: {
name: 'Icônes',
short_name: 'Icônes',
icons: [
{
src: '/android-chrome-192x192.png',
sizes: '192x192',
type: 'image/png',
},
{
src: '/android-chrome-512x512.png',
sizes: '512x512',
type: 'image/png',
},
],
},
injectManifest: {
// collections-meta.json ~7.5MB
maximumFileSizeToCacheInBytes: 10 * 1024 * 1024,
},
integration: {
configureOptions(viteConfig, options) {
if (viteConfig.command === 'build')
options.includeAssets = fg.sync('**/*.*', { cwd: join(process.cwd(), 'public'), onlyFiles: true })
},
},
devOptions: {
enabled: process.env.SW_DEV === 'true',
/* when using generateSW the PWA plugin will switch to classic */
type: 'module',
navigateFallback: 'index.html',
},
}),
UnoCSS(),
],
define: {
__BUILD_TIME__: JSON.stringify(dayjs().format('YYYY/MM/DD HH:mm')),
PWA: !isElectron && (process.env.NODE_ENV === 'production' || process.env.SW_DEV === 'true'),
},
resolve: {
alias: {
'iconify-icon': resolve(__dirname, 'node_modules/iconify-icon/dist/iconify-icon.mjs'),
},
},
worker: {
format: 'es',
rollupOptions: {
treeshake: true,
},
plugins: () => [
SvgPackerVitePlugin(),
],
},
}
})