aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/frontend/vite.config.ts
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <kristof@marussy.com>2022-08-12 19:54:46 +0200
committerLibravatar Kristóf Marussy <kristof@marussy.com>2022-08-12 19:54:46 +0200
commitd22c3b0c257f5daf5b401988a35ab9ce981a2341 (patch)
tree0a661c927c37b52197326d1c05e211daf9bd19e5 /subprojects/frontend/vite.config.ts
parentfix(language): rule parsing test (diff)
downloadrefinery-d22c3b0c257f5daf5b401988a35ab9ce981a2341.tar.gz
refinery-d22c3b0c257f5daf5b401988a35ab9ce981a2341.tar.zst
refinery-d22c3b0c257f5daf5b401988a35ab9ce981a2341.zip
refactor(frontend): move from Webpack to Vite
Also overhaulds the building and linting for frontend assets.
Diffstat (limited to 'subprojects/frontend/vite.config.ts')
-rw-r--r--subprojects/frontend/vite.config.ts92
1 files changed, 92 insertions, 0 deletions
diff --git a/subprojects/frontend/vite.config.ts b/subprojects/frontend/vite.config.ts
new file mode 100644
index 00000000..9cb426cf
--- /dev/null
+++ b/subprojects/frontend/vite.config.ts
@@ -0,0 +1,92 @@
1import { readFileSync } from 'node:fs';
2import path from 'node:path';
3import { fileURLToPath } from 'node:url';
4
5import { lezer } from '@lezer/generator/rollup';
6import react from '@vitejs/plugin-react';
7import { defineConfig } from 'vite';
8import injectPreload from 'vite-plugin-inject-preload';
9
10const thisDir = path.dirname(fileURLToPath(import.meta.url));
11
12const mode = process.env.MODE || 'development';
13const isDevelopment = mode === 'development';
14
15function portNumberOrElse(envName: string, fallback: number): number {
16 const value = process.env[envName];
17 return value ? parseInt(value, 10) : fallback;
18}
19
20const listenHost = process.env.LISTEN_HOST || 'localhost';
21const listenPort = portNumberOrElse('LISTEN_PORT', 1313);
22const apiHost = process.env.API_HOST || listenHost;
23const apiPort = portNumberOrElse('API_PORT', 1312);
24const apiSecure = apiPort === 443;
25const publicHost = process.env.PUBLIC_HOST || listenHost;
26const publicPort = portNumberOrElse('PUBLIC_PORT', listenPort);
27
28const { name: packageName, version: packageVersion } = JSON.parse(
29 readFileSync(path.join(thisDir, 'package.json'), 'utf8'),
30) as { name: string; version: string };
31process.env.VITE_PACKAGE_NAME ??= packageName;
32process.env.VITE_PACKAGE_VERSIOn ??= packageVersion;
33
34export default defineConfig({
35 logLevel: 'info',
36 mode,
37 root: thisDir,
38 cacheDir: path.join(thisDir, 'build/vite/cache'),
39 plugins: [
40 react({
41 babel: {
42 // Gets rid of deoptimization warnings for large chunks.
43 // We don't need to minify here, because the output of Babel
44 // will get passed to esbuild anyways.
45 compact: false,
46 minified: false,
47 },
48 }),
49 injectPreload({
50 files: [
51 {
52 match:
53 /(?:jetbrains-mono-latin-variable-wghtOnly-(?:italic|normal)|roboto-latin-(400|500)-normal).+\.woff2/,
54 attributes: {
55 type: 'font/woff2',
56 as: 'font',
57 crossorigin: 'anonymous',
58 },
59 },
60 ],
61 }),
62 lezer(),
63 ],
64 base: '',
65 define: {
66 __DEV__: JSON.stringify(isDevelopment), // For MobX
67 },
68 build: {
69 assetsDir: '.',
70 outDir: path.join('build/vite', mode),
71 emptyOutDir: true,
72 sourcemap: isDevelopment,
73 minify: !isDevelopment,
74 },
75 server: {
76 host: listenHost,
77 port: listenPort,
78 strictPort: true,
79 proxy: {
80 '/xtext-service': {
81 target: `${apiSecure ? 'https' : 'http'}://${apiHost}:${apiPort}`,
82 ws: true,
83 secure: apiSecure,
84 },
85 },
86 hmr: {
87 host: publicHost,
88 clientPort: publicPort,
89 path: '/vite',
90 },
91 },
92});