Repository navigation
Expand file tree
/
Copy pathvite.config.app.js
More file actions
130 lines (115 loc) · 3.73 KB
/
Copy pathvite.config.app.js
File metadata and controls
130 lines (115 loc) · 3.73 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
127
128
129
130
import { defineConfig, loadEnv } from 'vite';
import react from '@vitejs/plugin-react';
import { createHtmlPlugin } from 'vite-plugin-html';
import importMetaUrlPlugin from '@codingame/esbuild-import-meta-url-plugin';
import { viteStaticCopy } from 'vite-plugin-static-copy';
import nodePolyfills from 'rollup-plugin-polyfill-node';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { buildDefines, logger } from './vite/shared.js';
import { fsShim } from './vite/plugins/fs-shim.js';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), 'VITE_');
return {
customLogger: logger,
mode: 'production',
base: '/',
define: buildDefines(),
plugins: [
fsShim(),
// Polyfill remaining Node built-ins (util, events, stream, buffer, etc.) before
// Vite externalizes them. Must be 'pre' so resolveId runs ahead of Vite's own
// browser-externalization logic, which otherwise wins the module-resolution race.
{ ...nodePolyfills(), enforce: 'pre' },
react(),
// Copy tree-sitter WASM files to root for worker access
viteStaticCopy({
targets: [
{
src: 'node_modules/@swagger-api/apidom-parser-adapter-json/wasm/tree-sitter-json.wasm',
dest: '.',
},
{
src: 'node_modules/@swagger-api/apidom-parser-adapter-yaml-1-2/wasm/tree-sitter-yaml.wasm',
dest: '.',
},
],
}),
createHtmlPlugin({
minify: true,
inject: {
data: {
VITE_VERSION: env.VITE_VERSION || '5.2.0',
},
},
}),
],
optimizeDeps: {
esbuildOptions: {
plugins: [importMetaUrlPlugin],
},
include: [
'vscode-textmate',
'vscode-oniguruma',
'@vscode/vscode-languagedetection',
'@babel/runtime-corejs3/core-js/aggregate-error',
'ramda',
'ramda-adjunct',
'@stoplight/spectral-core',
'@stoplight/spectral-functions',
'@stoplight/spectral-runtime',
],
},
assetsInclude: ['**/*.wasm'],
build: {
outDir: 'build',
sourcemap: true,
emptyOutDir: true,
target: 'esnext',
commonjsOptions: {
transformMixedEsModules: true,
include: [/node_modules\/@stoplight\/spectral/, /node_modules\/minim/, /node_modules/],
},
chunkSizeWarningLimit: 1000,
rollupOptions: {
input: {
main: path.resolve(__dirname, 'index.html'),
},
output: {
hoistTransitiveImports: false,
entryFileNames: 'static/js/[name].[hash].js',
chunkFileNames: 'static/js/[name].[hash].chunk.js',
assetFileNames: (assetInfo) => {
if (assetInfo.name && assetInfo.name.endsWith('.css')) {
return 'static/css/[name].[hash].css';
}
return 'static/media/[name].[hash][extname]';
},
},
external: ['esprima'],
onwarn(warning, warn) {
if (warning.code === 'EVAL') return;
warn(warning);
},
},
},
resolve: {
alias: [
{ find: 'plugins', replacement: path.resolve(__dirname, 'src/plugins') },
{ find: 'presets', replacement: path.resolve(__dirname, 'src/presets') },
{ find: 'fs', replacement: path.resolve(__dirname, 'src/polyfills/fs-shim.js') },
],
},
worker: {
format: 'es',
rollupOptions: {
output: {
entryFileNames: 'static/js/[name].[hash].js',
},
},
plugins: () => [fsShim(), { ...nodePolyfills(), enforce: 'pre' }],
},
};
});