-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Expand file tree
/
Copy pathvite.config.js
More file actions
82 lines (77 loc) · 2.39 KB
/
Copy pathvite.config.js
File metadata and controls
82 lines (77 loc) · 2.39 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
import { defineConfig, loadEnv } from 'vite';
import react from '@vitejs/plugin-react';
import nodePolyfills from 'rollup-plugin-polyfill-node';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { buildDefines, logger } from './vite/shared.js';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
process.env = { ...process.env, ...loadEnv(mode, process.cwd()) };
return {
customLogger: logger,
base: '/',
server: {
// Ensure workers are served with correct MIME type
fs: {
strict: false,
},
},
plugins: [react()],
define: {
global: 'globalThis',
...buildDefines(),
},
optimizeDeps: {
rolldownOptions: {
plugins: [
// Must run before nodePolyfills so it resolves 'fs' to our shim
// instead of the empty stub that nodePolyfills provides for 'fs'.
{
name: 'fs-shim',
resolveId(id) {
if (id === 'fs') return path.resolve(__dirname, 'src/polyfills/fs-shim.js');
return null;
},
},
nodePolyfills(),
],
},
include: [
'@codingame/monaco-vscode-api/workers/editor.worker',
'monaco-editor/esm/vs/editor/editor.worker.js',
],
},
assetsInclude: ['**/*.wasm'],
resolve: {
alias: [
{ find: 'plugins', replacement: '/src/plugins' },
{ find: 'presets', replacement: '/src/presets' },
{ find: 'fs', replacement: '/src/polyfills/fs-shim.js' },
],
},
worker: {
format: 'es',
plugins: () => [],
},
build: {
commonjsOptions: { transformMixedEsModules: true },
sourcemap: false,
sourcemapExcludeSources: true,
target: 'esnext',
outDir: 'build',
chunkSizeWarningLimit: 1000,
rollupOptions: {
plugins: [nodePolyfills()],
onwarn(warning, warn) {
if (warning.message.includes('Use of eval')) return;
// Third-party packages (web-tree-sitter, avsc, spectral) reference Node
// built-ins that Vite externalizes; they fall back gracefully at runtime.
if (warning.message.includes('has been externalized for browser compatibility')) return;
warn(warning);
},
},
},
};
});