-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvite.config.js
More file actions
152 lines (139 loc) · 4.03 KB
/
vite.config.js
File metadata and controls
152 lines (139 loc) · 4.03 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import modify from 'rollup-plugin-modify';
import unassert from 'rollup-plugin-unassert';
import { defineConfig } from 'vite';
// Using js/ts compatibility from https://github.com/vitejs/vite/issues/3040
/*
- Build failure, trying `npm run build --max-old-space-size`
- export NODE_OPTIONS=--max-old-space-size=32768
- Maybe we should... ditch loading all the data? (remove references for the collections tests?)
*/
let chunkId = 0;
// https://vitejs.dev/config/
export default defineConfig({
base: '',
resolve: {
alias: [
{
find: /^(.*)\.js$/,
replacement: '$1',
},
],
},
// Because of https://github.com/vitejs/vite/issues/12434?
optimizeDeps: {
exclude: ['phet-lib', 'tesseract.js', 'culori', 'pako'],
entries: [],
},
plugins: [
// Work around paper.js stuff
modify({
find: 'self = self || window.self;',
replace: '',
}),
modify({
find: 'var window = self.window,',
replace: '',
}),
modify({
find: 'document = self.document;',
replace: 'var document = self.document;',
}),
// Work around a Display.ts issue where we alias self and THEN try to access window
modify({
find: /const self = this;\s*\(/gm,
replace: 'const _self = this;\n(',
}),
modify({
find: 'self._requestAnimationFrameID = window.requestAnimationFrame( step, self._domElement );',
replace: '_self._requestAnimationFrameID = self.requestAnimationFrame( step, _self._domElement );',
}),
modify({
find: 'self.updateDisplay();',
replace: '_self.updateDisplay();',
}),
// Redirect window to self
modify({
find: /([^.a-zA-Z0-9_])window(\.|\?\.|\[)/g,
replace: (match, prefix, suffix) => `${prefix}self${suffix}`,
}),
// Standalone window to self
modify({
find: /(\s+)window(\s+)/g,
replace: (match, prefix, suffix) => `${prefix}self${suffix}`,
}),
modify({
find: /\(\s*window\s*\)/g,
replace: '(self)',
}),
modify({
find: /\(\s*window\s*,/g,
replace: '(self,',
}),
modify({
find: /\(\s*!window\s*\)/g,
replace: '(!self)',
}),
modify({
find: /in window;/g,
replace: 'in self;',
}),
],
build: {
rollupOptions: {
input: {
index: '/index.html',
play: '/play.html',
'rule-explorer': '/rule-explorer.html',
rule: '/rule.html',
'scan-test': '/scan-test.html',
'solver-fuzz': '/solver-fuzz.html',
'discover-rules': '/discover-rules.html',
'rules-test': '/rules-test.html',
'rule-image': '/rule-image.html',
'curated-rules': '/curated-rules.html',
'filtered-rules': '/filtered-rules.html',
'formal-concept-analysis': '/formal-concept-analysis.html',
'pattern-boards': '/pattern-boards.html',
hooks: '/hooks.html',
'test/model-tests': '/test/model-tests.html',
'test/correctness-tests': '/test/correctness-tests.html',
},
output: {
chunkFileNames: () => `chunk-${chunkId++}.js`,
entryFileNames: () => `entry-${chunkId++}.js`,
},
plugins: [
unassert({
// include: [ '**/**.js', '**/**.ts' ]
}),
// TODO: why are these extra ones needed? This is a wreck
// Redirect window to self
modify({
find: /([^.a-zA-Z0-9_])window(\.|\?\.|\[)/g,
replace: (match, prefix, suffix) => `${prefix}self${suffix}`,
}),
// Standalone window to self
modify({
find: /(\s+)window(\s+)/g,
replace: (match, prefix, suffix) => `${prefix}self${suffix}`,
}),
modify({
find: /\(\s*window\s*\)/g,
replace: '(self)',
}),
modify({
find: /\(\s*window\s*,/g,
replace: '(self,',
}),
modify({
find: /\(\s*!window\s*\)/g,
replace: '(!self)',
}),
modify({
find: /in window;/g,
replace: 'in self;',
}),
],
},
},
});