-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathvite.config.ts
More file actions
82 lines (77 loc) · 2.23 KB
/
Copy pathvite.config.ts
File metadata and controls
82 lines (77 loc) · 2.23 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 fs from 'node:fs';
import path from 'node:path';
import react from '@vitejs/plugin-react';
import type { AliasOptions } from 'vite';
import { defaultClientConditions, defaultServerConditions } from 'vite';
import { defineConfig } from 'vitest/config';
// https://vitejs.dev/config/
export default () => {
let resolveAliases: AliasOptions = [];
if (process.env.WITH_PROFILING) {
resolveAliases = [
{ find: 'react-dom/client', replacement: 'react-dom/profiling' },
{ find: 'scheduler/tracing', replacement: 'scheduler/tracing-profiling' },
];
}
const isMonorepo = checkMonorepo();
return defineConfig({
base: './',
build: {
sourcemap: 'inline',
rolldownOptions: {
output: {
strictExecutionOrder: true,
codeSplitting: {
groups: [
{
name: 'openchemlib',
test: 'node_modules/openchemlib/',
entriesAware: true,
},
{
name: 'd3',
test: /node_modules\/d3[-/]/,
entriesAware: true,
},
{
name: 'blueprint',
test: 'node_modules/@blueprintjs/',
entriesAware: true,
},
{
name: 'vendor',
test: 'node_modules/',
entriesAware: true,
maxSize: 500_000,
},
],
},
},
},
minify: process.env.NO_MINIFY ? false : 'oxc',
},
plugins: [react()],
resolve: {
conditions: isMonorepo
? ['nmrium-internal', ...defaultClientConditions]
: undefined,
alias: resolveAliases,
},
ssr: {
resolve: {
conditions: isMonorepo
? ['nmrium-internal', ...defaultServerConditions]
: undefined,
},
},
test: {
include: ['./src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
},
});
};
function checkMonorepo() {
const monorepoPkg = path.join(import.meta.dirname, '..', 'package.json');
if (!fs.existsSync(monorepoPkg)) return false;
const pkg = JSON.parse(fs.readFileSync(monorepoPkg, 'utf8'));
return pkg.name === '@zakodium/nmrium-monorepo';
}