-
Notifications
You must be signed in to change notification settings - Fork 1
/
cli.vite.ts
78 lines (74 loc) · 2.73 KB
/
cli.vite.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
import { execSync } from 'node:child_process';
import path from 'node:path';
import { resolve } from 'node:path';
import { defineConfig } from 'vite';
//---------------------------------------------------------------------------+
// IMPORTANT README |
//---------------------------------------------------------------------------+
// if you have stumbled upon this file because you have some kind of import
// error then you probably need to know what this is all about.
//
// the runtime/Client should remain agnostic to the environment it is loaded in.
// this is because we run the Client in both socket and in nodejs environments.
//
// this means that Client (or anything that Client imports) should not depend on
// any socket library that requires the socket runtime
//
// _some_ socket libraries are compatible with nodejs and can be imported but
// most cannot.
//
// you should make Client accept dependencies via the config so that compatible
// deps can be injected during Client instantiation, rather than being imported
// directly. and use `import type` to avoid importing the actual implementation.
//
// see what is being done for the Buffer, Encryption, NAT, network
//
// see src/cli for how the client is loaded from nodejs see src/gui/workers for
// how the client is loaded from a worker
//
// if you _really_ think the import should work, then you can add to the list of
// resolve.alias below.
//
//---------------------------------------------------------------------------+
// exec ssc env to find the environment values
function getSocketEnv(name: string) {
const out = execSync('ssc env').toString();
const lines = out.split('\n').map((line) => line.trim());
for (const line of lines) {
if (line.startsWith(`${name}=`)) {
return line.split('=')[1];
}
}
throw new Error(
`Failed to find ${name} in ssc env. is ssc installed correctly?`,
);
}
const SOCKET_HOME_API = getSocketEnv('SOCKET_HOME_API');
console.log('SOCKET_HOME_API:', SOCKET_HOME_API);
export default defineConfig({
envPrefix: 'SS',
mode: 'production',
resolve: {
alias: {
'socket:dgram': 'node:dgram',
'socket:buffer': path.join(SOCKET_HOME_API, 'buffer.js'),
'runtime:platform': path.resolve(
__dirname,
'src/runtime/platform/node.ts',
),
},
},
build: {
ssr: true,
outDir: 'dist',
target: 'esnext',
minify: false,
chunkSizeWarningLimit: 2000,
lib: {
formats: ['es'],
entry: [resolve(__dirname, './src/cli/cli.ts')],
},
emptyOutDir: false,
copyPublicDir: false,
},
});