-
Notifications
You must be signed in to change notification settings - Fork 2
/
vite.config.js
119 lines (102 loc) · 3.31 KB
/
vite.config.js
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
/* global process, __dirname */
import fs from 'fs';
import path from 'path';
import {flowPlugin, esbuildFlowPlugin} from '@bunchtogether/vite-plugin-flow';
import react from '@vitejs/plugin-react';
import {defineConfig, loadEnv} from 'vite';
// https://vitejs.dev/config/
export default defineConfig(({command, mode}) => {
const env = loadEnv(mode, process.cwd(), '');
return {
plugins: [
react({
// Ensure this Babel config is similar with babel.config.cjs
babel: {
presets: ['@babel/preset-flow'],
plugins: ['babel-plugin-syntax-hermes-parser'],
},
}),
flowPlugin(),
],
optimizeDeps: {
esbuildOptions: {
plugins: [esbuildFlowPlugin()],
},
},
build: {
assetsInlineLimit: 0,
chunkSizeWarningLimit: 3000, // level_data is really big
},
server: {
headers: getServerHeaders(env),
https:
env.SSL_KEY_FILE != null && env.SSL_CRT_FILE != null
? {
key: fs.readFileSync(path.resolve(__dirname, env.SSL_KEY_FILE)),
cert: fs.readFileSync(path.resolve(__dirname, env.SSL_CRT_FILE)),
}
: false,
port: 3000,
// https://mattjennings.io/blog/how-to-enable-hmr-for-sveltekit-on-gitpod
hmr: process.env.GITPOD_WORKSPACE_URL
? {
// removes the protocol and replaces it with the port we're connecting to
host: process.env.GITPOD_WORKSPACE_URL.replace('https://', '3000-'),
protocol: 'wss',
clientPort: 443,
}
: true,
},
};
});
function getServerHeaders(env) {
const inGameScreenshotHost = env.VITE_IN_GAME_SCREENSHOT_URL_PREFIX;
const sprite = env.VITE_SPRITES_URL_PREFIX;
// Keep this in sync with /public/_headers
return {
'X-Powered-By': 'Picnic',
'X-Content-Type-Options': 'nosniff',
'X-XSS-Protection': '0',
'X-Frame-Options': 'DENY',
// 'Strict-Transport-Security': 'max-age=31536000', // irrelevant during dev
'Cross-Origin-Embedder-Policy': 'require-corp',
'Cross-Origin-Opener-Policy': 'same-origin',
'Cross-Origin-Resource-Policy': 'same-origin',
'Permissions-Policy': 'interest-cohort=()',
'Content-Security-Policy': [
"default-src 'self'",
// unsafe-inline: For Vite dev server
"script-src 'self' 'unsafe-inline'",
[
'connect-src',
"'self'",
// https://github.com/w3c/webappsec-csp/issues/7
// For Vite dev server, only needed on old Safari versions, uncomment if needed
// 'ws://127.0.0.1:3000',
process.env.GITPOD_WORKSPACE_URL
? process.env.GITPOD_WORKSPACE_URL.replace(
'https://',
'wss://3000-'
) + ':3000'
: '',
].join(' '),
// unsafe-inline: For react-select (https://github.com/JedWatson/react-select/issues/2030)
"style-src 'self' 'unsafe-inline'",
// data: Inline images
// blob: Read images to canvas for terrain editor
[
'img-src',
"'self'",
'data:',
'blob:',
inGameScreenshotHost ?? '',
sprite ?? '',
].join(' '),
process.env.GITPOD_WORKSPACE_URL ? '' : "frame-ancestors 'none'",
"base-uri 'none'",
"object-src 'none'",
].join(';'),
'Feature-Policy':
"accelerometer 'none';ambient-light-sensor 'none';battery 'none';bluetooth 'none';camera 'none';display-capture 'none';gamepad 'none';geolocation 'none';gyroscope 'none';hid 'none';magnetometer 'none';microphone 'none';midi 'none';payment 'none';serial 'none';usb 'none';xr-spatial-tracking 'none';",
};
}