-
Notifications
You must be signed in to change notification settings - Fork 120
Expand file tree
/
Copy pathvite.esm.config.js
More file actions
86 lines (78 loc) · 2.54 KB
/
vite.esm.config.js
File metadata and controls
86 lines (78 loc) · 2.54 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
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import path from 'path';
// Plugin to sanitize problematic regex patterns in the bundle
const sanitizeRegexPlugin = () => {
return {
name: 'sanitize-regex',
generateBundle(options, bundle) {
Object.keys(bundle).forEach(fileName => {
const chunk = bundle[fileName];
if (chunk.type === 'chunk' && chunk.code) {
let code = chunk.code;
// Fix overly permissive character range [$_A-z] -> [$_A-Za-z]
code = code.replace(/\[\$_A-z\]/g, '[$_A-Za-z]');
// Fix incomplete string escaping in escapeGroup function specifically
code = code.replace(
/return\s+group\.replace\(\/\(\[=!:\$\\?\/\(\)\]\)\/g,\s*"\\\\?\$1"\);/g,
'return group.replace(/([=!:$\\/()])/g, "\\\\\\\\$1");'
);
// Fix the exact pattern from the error
code = code.replace(
'group.replace(/([=!:$\\/()])/g, "\\\\$1")',
'group.replace(/([=!:$\\/()])/g, "\\\\\\\\$1")'
);
// Broader pattern for any replace with this specific regex
code = code.replace(
/\.replace\(\/\(\[=!:\$\\\/\(\)\]\)\/g,\s*"\\\\?\$1"\)/g,
'.replace(/([=!:$\\/()])/g, "\\\\\\\\$1")'
);
// Fix other problematic regex patterns
code = code.replace(/illegal:\s*\/\#\(\?\!\[\$_A-z\]\)\//g, 'illegal: /#(?![\\$_A-Za-z])/');
chunk.code = code;
}
});
},
};
};
export default defineConfig({
plugins: [react(), sanitizeRegexPlugin()],
build: {
outDir: 'esm',
emptyOutDir: true,
minify: 'terser',
copyPublicDir: false,
lib: {
entry: path.resolve(__dirname, 'src/utils/viz-entry.js'),
fileName: () => 'kedro-viz.mjs',
formats: ['es'],
},
rollupOptions: {
external: ['plotly.js-dist-min', 'mermaid'],
output: {
format: 'es',
entryFileNames: 'kedro-viz.mjs',
exports: 'auto',
paths: {
'plotly.js-dist-min': 'https://cdn.jsdelivr.net/npm/plotly.js-dist-min@2.26.0/+esm',
'mermaid': 'https://cdn.jsdelivr.net/npm/mermaid@11/dist/mermaid.esm.min.mjs',
},
},
},
terserOptions: {
compress: {
drop_console: true,
},
output: {
comments: false,
},
},
sourcemap: false,
},
resolve: {
extensions: ['.js', '.jsx'],
},
define: {
'process.env.NODE_ENV': '"production"',
},
});