forked from cheeaun/phanpy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.js
157 lines (153 loc) · 4.06 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import preact from '@preact/preset-vite';
import { execSync } from 'child_process';
import fs from 'fs';
import { resolve } from 'path';
import { defineConfig, loadEnv, splitVendorChunkPlugin } from 'vite';
import generateFile from 'vite-plugin-generate-file';
import htmlPlugin from 'vite-plugin-html-config';
import { VitePWA } from 'vite-plugin-pwa';
import removeConsole from 'vite-plugin-remove-console';
const { NODE_ENV } = process.env;
const {
VITE_CLIENT_NAME: CLIENT_NAME,
VITE_CLIENT_ID: CLIENT_ID,
VITE_APP_ERROR_LOGGING: ERROR_LOGGING,
} = loadEnv('production', process.cwd());
const now = new Date();
const commitHash = execSync('git rev-parse --short HEAD').toString().trim();
const rollbarCode = fs.readFileSync(
resolve(__dirname, './rollbar.js'),
'utf-8',
);
// https://vitejs.dev/config/
export default defineConfig({
base: './',
mode: NODE_ENV,
define: {
__BUILD_TIME__: JSON.stringify(now),
__COMMIT_HASH__: JSON.stringify(commitHash),
},
server: {
host: true,
},
plugins: [
preact(),
splitVendorChunkPlugin(),
removeConsole({
includes: ['log', 'debug', 'info', 'warn', 'error'],
}),
htmlPlugin({
headScripts: ERROR_LOGGING ? [rollbarCode] : [],
}),
generateFile([
{
type: 'json',
output: './version.json',
data: {
buildTime: now,
commitHash,
},
},
]),
VitePWA({
manifest: {
id: CLIENT_ID,
name: CLIENT_NAME,
short_name: CLIENT_NAME,
description: 'Follow your interests across social networks!',
theme_color: '#ffffff',
icons: [
{
src: 'logo-192.png',
sizes: '192x192',
type: 'image/png',
},
{
src: 'logo-512.png',
sizes: '512x512',
type: 'image/png',
},
{
src: 'logo-maskable-512.png',
sizes: '512x512',
type: 'image/png',
purpose: 'maskable',
},
],
screenshots : [
{
'src': 'agora-social-desktop-1.png',
'sizes': '1280x720',
'type': 'image/webp',
'form_factor': 'wide',
'label': ''
},
{
'src': 'agora-social-desktop-2.png',
'sizes': '1280x720',
'type': 'image/webp',
'form_factor': 'wide',
'label': ''
},
{
'src': 'agora-social-desktop-3.png',
'sizes': '1280x720',
'type': 'image/webp',
'form_factor': 'wide',
'label': ''
},
{
'src': 'agora-social-mobile-1.png',
'sizes': '1280x720',
'type': 'image/webp',
'form_factor': 'narrow',
'label': ''
},
{
'src': 'agora-social-mobile-2.png',
'sizes': '1280x720',
'type': 'image/webp',
'form_factor': 'narrow',
'label': ''
},
{
'src': 'agora-social-mobile-3.png',
'sizes': '1280x720',
'type': 'image/webp',
'form_factor': 'narrow',
'label': ''
},
],
},
strategies: 'injectManifest',
injectRegister: 'inline',
injectManifest: {
// Prevent "Unable to find a place to inject the manifest" error
injectionPoint: undefined,
},
devOptions: {
enabled: NODE_ENV === 'development',
type: 'module',
},
}),
],
build: {
sourcemap: true,
rollupOptions: {
treeshake: false,
input: {
main: resolve(__dirname, 'index.html'),
compose: resolve(__dirname, 'compose/index.html'),
},
output: {
chunkFileNames: (chunkInfo) => {
const { facadeModuleId } = chunkInfo;
if (facadeModuleId && facadeModuleId.includes('icon')) {
return 'assets/icons/[name]-[hash].js';
}
return 'assets/[name]-[hash].js';
},
},
},
},
});