-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathvite.config.mts
More file actions
126 lines (123 loc) · 3.36 KB
/
vite.config.mts
File metadata and controls
126 lines (123 loc) · 3.36 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
import react from '@vitejs/plugin-react';
import dotenv from 'dotenv';
import fs from 'fs';
import path from 'path';
import { defineConfig } from 'vite';
import obfuscator from 'vite-plugin-bundle-obfuscator';
import { nodePolyfills } from 'vite-plugin-node-polyfills';
import { viteStaticCopy } from 'vite-plugin-static-copy';
import svgr from 'vite-plugin-svgr';
dotenv.config();
const ASSETS_DIR = 'static';
export default defineConfig({
base: process.env.PUBLIC_URL ?? '/',
plugins: [
react(),
svgr(),
nodePolyfills({
globals: {
process: true,
Buffer: true,
global: true,
},
protocolImports: true,
}),
viteStaticCopy({
targets: [
{
src: 'node_modules/@dashlane/pqc-kem-kyber512-browser/dist/pqc-kem-kyber512.wasm',
dest: ASSETS_DIR,
},
],
}),
{
name: 'serve-wasm-on-dev',
apply: 'serve',
configureServer(server) {
server.middlewares.use((req, res, next) => {
if (req.url?.endsWith('pqc-kem-kyber512.wasm')) {
const wasmPath = path.resolve(
__dirname,
'node_modules/@dashlane/pqc-kem-kyber512-browser/dist/pqc-kem-kyber512.wasm',
);
const wasm = fs.readFileSync(wasmPath);
res.setHeader('Content-Type', 'application/wasm');
res.end(wasm);
return;
}
next();
});
},
},
obfuscator({
log: false,
enable: true,
autoExcludeNodeModules: true,
threadPool: true,
options: {
compact: true,
stringArray: true,
stringArrayThreshold: 1,
stringArrayCallsTransform: true,
stringArrayCallsTransformThreshold: 1,
stringArrayEncoding: ['base64', 'rc4'],
stringArrayIndexShift: true,
stringArrayRotate: true,
stringArrayShuffle: true,
stringArrayWrappersCount: 5,
stringArrayWrappersChainedCalls: true,
stringArrayWrappersParametersMaxCount: 5,
transformObjectKeys: true,
identifierNamesGenerator: 'hexadecimal',
splitStrings: true,
splitStringsChunkLength: 5,
unicodeEscapeSequence: true,
},
}),
],
envPrefix: ['REACT_APP_'],
build: {
outDir: 'build',
assetsDir: ASSETS_DIR,
},
preview: {
port: 3000,
open: true,
},
server: {
port: 3000,
open: true,
},
resolve: {
preserveSymlinks: process.env.NODE_ENV === 'development',
alias: {
app: path.resolve(__dirname, 'src/app'),
components: path.resolve(__dirname, 'src/components'),
assets: path.resolve(__dirname, 'src/assets'),
hooks: path.resolve(__dirname, 'src/hooks'),
services: path.resolve(__dirname, 'src/services'),
utils: path.resolve(__dirname, 'src/utils'),
use_cases: path.resolve(__dirname, 'src/use_cases'),
views: path.resolve(__dirname, 'src/views'),
assert: 'assert',
buffer: 'buffer',
path: 'path-browserify',
crypto: 'crypto-browserify',
http: 'stream-http',
https: 'https-browserify',
os: 'os-browserify/browser',
process: 'process/browser',
stream: 'stream-browserify',
zlib: 'browserify-zlib',
util: 'util',
url: 'url',
},
},
optimizeDeps: {
esbuildOptions: {
define: {
global: 'globalThis',
},
},
},
});