-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathvite.config.js
137 lines (130 loc) · 3.81 KB
/
vite.config.js
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
// @ts-check
import fs, { promises as fsp } from 'fs'
import path from 'path'
import vue from '@vitejs/plugin-vue'
import { VitePWA as pwa } from 'vite-plugin-pwa'
import components from 'unplugin-vue-components/vite'
import yaml from '@rollup/plugin-yaml'
import unocss from 'unocss/vite'
import { defineConfig } from 'vite'
import template from 'lodash.template'
import simpleGit from 'simple-git'
import { version } from './package.json'
/**
* Vite Configuration File
*
* Docs: https://vitejs.dev/config/
*/
export default defineConfig(async ({ mode }) => {
/**
* @type Promise<unknown>[]
*/
const promises = []
const data = {
mode,
isDev: mode !== 'production',
isProd: mode === 'production',
version,
gitLatest: (await simpleGit().log({ maxCount: 1 })).latest,
date: new Date(),
}
/**
* @type string
*/
const banner = '/*! PatchyVideo/Platinum by VoileLabs */'
/* create __generated__ dir */
{
/**
* @type string[]
*/
const list = []
for (const dir of list) promises.push(fsp.mkdir(path.resolve(__dirname, 'packages', dir, '__generated__')))
promises.push(fsp.mkdir(path.resolve(__dirname, '__generated__')))
}
/* copy license */
promises.push(fsp.copyFile(path.resolve(__dirname, './LICENSE'), path.resolve(__dirname, './public/LICENSE')))
await Promise.allSettled(promises)
return defineConfig({
resolve: {
alias: [
{ find: '@', replacement: path.resolve(__dirname, './packages/') },
{ find: '@@', replacement: path.resolve(__dirname, './') },
],
},
define: {
'__DEV__': JSON.stringify(mode !== 'production'),
'import.meta.env.VITE_APP_VERSION': JSON.stringify(version),
'import.meta.env.VITE_COMMIT_HASH': JSON.stringify(data.gitLatest.hash),
'import.meta.env.VITE_APP_BUILDTIME': JSON.stringify(data.date.toISOString()),
'import.meta.env.VITE_DATE_FNS_LOCALE': JSON.stringify(
fs.readdirSync(path.resolve(__dirname, './node_modules/date-fns/esm/locale'), { withFileTypes: true })
.filter(file => file.isDirectory() && !file.name.startsWith('_'))
.map(file => file.name),
),
},
optimizeDeps: {
include: ['@apollo/client/core', '@apollo/client/utilities'],
exclude: ['@apollo/client'],
},
plugins: [
yaml(),
vue(),
components({
dirs: ['packages/layouts/components'],
dts: '__generated__/viteComponents.d.ts',
}),
unocss(),
pwa({
strategies: 'injectManifest',
srcDir: 'packages/main',
filename: 'sw.ts',
includeAssets: ['favicon.ico', 'robots.txt', 'apple-touch-icon.png'],
injectManifest: {
globPatterns: ['LICENSE', 'index.html', 'assets/**.{js,css,jpg,png}'],
},
manifest: {
name: 'PatchyVideo',
short_name: 'PatchyVideo',
description: 'The video-indexing platform that helps you find your favorites.',
start_url: 'index.html',
display: 'standalone',
icons: [
{
src: '/android-chrome-192x192.png',
sizes: '192x192',
type: 'image/png',
},
{
src: '/android-chrome-512x512.png',
sizes: '512x512',
type: 'image/png',
},
],
theme_color: '#ffffff',
background_color: '#ffffff',
},
}),
{
name: 'html-template',
transformIndexHtml: {
enforce: 'pre',
transform(html) {
return template(html)(data)
},
},
},
],
build: {
sourcemap: true,
rollupOptions: {
output: {
banner,
},
},
},
esbuild: {
// to reduce code size (~50KiB decrease, what??)
charset: 'utf8',
},
})
})