-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
87 lines (80 loc) · 2.83 KB
/
vite.config.ts
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
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import wasm from 'vite-plugin-wasm';
import topLevelAwait from 'vite-plugin-top-level-await';
import * as path from "node:path";
import eslint from "vite-plugin-eslint";
//because __dirname was showing undefined
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
import { visualizer } from "rollup-plugin-visualizer";
import {ViteImageOptimizer} from "vite-plugin-image-optimizer";
import {nodePolyfills} from "vite-plugin-node-polyfills";
const host = process.env.TAURI_DEV_HOST;
// Use top-level await if necessary to resolve any async configuration steps before defining the config
const main = async (ReactCompilerConfig: string | boolean | object) => {
// If you have asynchronous steps, resolve them here
return defineConfig({
plugins: [
react({
babel: {
plugins: [
["babel-plugin-react-compiler",
ReactCompilerConfig],
],
}
}), eslint(),
visualizer(),
nodePolyfills(),
ViteImageOptimizer({})],
// PowerSync
optimizeDeps: {
// Don't optimize these packages as they contain web workers and WASM files.
// https://github.com/vitejs/vite/issues/11672#issuecomment-1415820673
exclude: ['@journeyapps/wa-sqlite', '@powersync/web'],
// But include js-logger from @powersync/web, otherwise app breaks.
// https://github.com/powersync-ja/powersync-js/pull/267
include: ['@powersync/web > js-logger'],
},
clearScreen: false,
server: {
port: 1420,
strictPort: true,
host: host || false,
hmr: host
? {
protocol: "ws",
host,
port: 1421,
}
: undefined,
watch: {
ignored: ["**/src-tauri/**"],
},
},
envPrefix: ['VITE_', 'TAURI_ENV_*'],
build: {
target: process.env.TAURI_ENV_PLATFORM == 'windows'
? 'chrome105'
: 'safari16',
minify: !process.env.TAURI_ENV_DEBUG ? 'esbuild' : false,
sourcemap: !!process.env.TAURI_ENV_DEBUG
},
worker: {
format: 'es',
plugins: () => [wasm(), topLevelAwait()],
},
resolve: {
alias: {
"@": path.resolve(__dirname, "./src"),
},
},
});
};
const ReactCompilerConfig = {
sources: (filename: string | string[]) => {
return filename.indexOf('src') !== -1;
}
};
export default main(ReactCompilerConfig);