-
-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathvite.config.ts
More file actions
175 lines (161 loc) · 4.58 KB
/
Copy pathvite.config.ts
File metadata and controls
175 lines (161 loc) · 4.58 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
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
172
173
174
175
import VueI18nPlugin from '@intlify/unplugin-vue-i18n/vite';
import VuePlugin from '@vitejs/plugin-vue';
import * as fs from 'fs';
import { dirname, resolve } from 'node:path';
import * as path from 'path';
import { fileURLToPath, URL } from 'url';
import { createLogger, defineConfig } from 'vite';
import loadVersion from 'vite-plugin-package-version';
/**
* Plugin is not bundled properly.
* After upgrading project to module type, the import got broken.
* We should only have to to loadVersion() but the function is
* actually on a "loadVersion.default".
* The following is a safe fallback solution.
* @see https://github.com/vitejs/vite/issues/5694
*/
const loadVersionPlugin = (loadVersion as any).default || loadVersion;
// https://vitejs.dev/config/
export default defineConfig({
publicDir: "static",
server: {
port: 8081,
allowedHosts: ['dev.twitchat.fr', 'localhost'],
proxy: {
'/api': {
target: 'http://localhost:3018',
changeOrigin: true,
secure: false,
},
},
},
plugins: [
VuePlugin(),
loadVersionPlugin(),
VueI18nPlugin({
/* options */
// locale messages resource pre-compile option
include: resolve(dirname(fileURLToPath(import.meta.url)), './i18n/**'),
runtimeOnly: false,
}),
{
/**
* Middleware that properly redirect any /overlay/ requests to the
* overlay/index.html page like production server does
*/
name: 'custom-html-middleware',
configureServer(server) {
server.middlewares.use((req, res, next) => {
const url = req.url;
if (url.startsWith('/overlay/label')) {
const overlayLabelHtmlPath = path.resolve(__dirname, 'overlayLabel.html');
if (fs.existsSync(overlayLabelHtmlPath)) {
res.setHeader('Content-Type', 'text/html');
res.end(fs.readFileSync(overlayLabelHtmlPath));
return;
}
}else
if (url.startsWith('/overlay/sfxr')) {
const overlaySfxrHtmlPath = path.resolve(__dirname, 'overlaySfxr.html');
if (fs.existsSync(overlaySfxrHtmlPath)) {
res.setHeader('Content-Type', 'text/html');
res.end(fs.readFileSync(overlaySfxrHtmlPath));
return;
}
}else
if (url.startsWith('/overlay/')) {
const overlayHtmlPath = path.resolve(__dirname, 'overlay.html');
if (fs.existsSync(overlayHtmlPath)) {
res.setHeader('Content-Type', 'text/html');
res.end(fs.readFileSync(overlayHtmlPath));
return;
}
}else
if (url.startsWith('/public/')) {
const publicHtmlPath = path.resolve(__dirname, 'public.html');
if (fs.existsSync(publicHtmlPath)) {
res.setHeader('Content-Type', 'text/html');
res.end(fs.readFileSync(publicHtmlPath));
return;
}
}else
if (url.startsWith('/popup/oauth')) {
const publicHtmlPath = path.resolve(__dirname, 'popupAuthResult.html');
if (fs.existsSync(publicHtmlPath)) {
res.setHeader('Content-Type', 'text/html');
res.end(fs.readFileSync(publicHtmlPath));
return;
}
}
next();
});
},
},
],
optimizeDeps: {
// exclude: ['tmi.js'],
esbuildOptions: {
target: 'es2020'
},
exclude: ['vue-facing-decorator'],
entries: []
},
esbuild: {
target: 'es2020'
},
build: {
target: 'es2020',
sourcemap: true,
rollupOptions: {
input: {
main: resolve(__dirname, 'index.html'),
overlay: resolve(__dirname, 'overlay.html'),
public: resolve(__dirname, 'public.html'),
overlayLabel: resolve(__dirname, 'overlayLabel.html'),
overlaySfxr: resolve(__dirname, 'overlaySfxr.html'),
popupAuthResult: resolve(__dirname, 'popupAuthResult.html'),
},
output: {
entryFileNames: "assets/[name]-[hash]-" + process.env.npm_package_version + ".js",
}
},
},
resolve: {
alias: [
{
find: "@",
replacement: fileURLToPath(new URL('./src_front', import.meta.url)),
},
{
find: 'vue-i18n',
replacement: 'vue-i18n/dist/vue-i18n.esm-bundler.js',
}
]
},
css: {
preprocessorOptions: {
less: {
//Requires proper version of less-loader to work. Tested with 8.0.0
additionalData: `
@import "./src_front/less/_includes.less";
`
}
}
},
customLogger: (() => {
const logger = createLogger();
const warn = logger.warn;
logger.warn = (message, options) => {
// Ignore specific warning
if (message.includes('dynamic import will not move module into another chunk')) {
return;
}
// Filter out wrong warning from Vite on <table> content
if (typeof message === 'string' && message.includes('<tr> cannot be child of <table>')) {
return;
}
warn(message, options);
};
return logger;
})(),
});