-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathvite.config.mts
More file actions
159 lines (154 loc) · 5.31 KB
/
vite.config.mts
File metadata and controls
159 lines (154 loc) · 5.31 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
153
154
155
156
157
158
159
/// <reference types="vitest/config" />
import { dirname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
import { type UserConfig, defineConfig } from 'vite';
import cssInjectedByJsPlugin from 'vite-plugin-css-injected-by-js';
import { playwright } from '@vitest/browser-playwright';
const __dirname = dirname(fileURLToPath(import.meta.url));
const EXAMPLES = [
'basic',
'classicWorkspace',
'graphAuthoring',
'i18n',
'rdfExplorer',
'sparql',
'stressTest',
'styleCustomization',
'wikidata'
];
export default defineConfig(({ command, mode }) => {
const common = {
mode: 'development',
build: {
rollupOptions: {
input: {
index: resolve(__dirname, './index.html'),
...Object.fromEntries(EXAMPLES.map(example =>
[example, resolve(__dirname, `./examples/${example}.html`)] as const
))
},
output: {
chunkFileNames: 'common/common-[hash].js',
},
},
},
resolve: {
alias: {
'@images': resolve(__dirname, './images'),
'@codicons': '@vscode/codicons/src/icons/',
}
},
css: {
modules: {
generateScopedName: '[name]__[local]',
}
},
define: {
'__REACTODIA_EXAMPLES__': JSON.stringify(EXAMPLES),
'__REACTODIA_WIKIDATA_ENDPOINT__': JSON.stringify(
process.env.WIKIDATA_ENDPOINT ?? 'https://query.wikidata.org/sparql'
),
},
} satisfies UserConfig;
if (mode === 'test') {
// Config to run unit tests with Vitest
return {
...common,
build: {
...common.build,
rollupOptions: undefined,
assetsInlineLimit: (path, _content) => (
/.resource.svg$/.test(path) ? false :
/.inline.svg$/.test(path) ? true :
undefined
),
},
test: {
browser: {
provider: playwright(),
enabled: true,
screenshotFailures: false,
instances: [
{browser: 'chromium'},
],
},
},
// To avoid warning about reloading due to
// "new dependencies optimized: react/jsx-dev-runtime":
optimizeDeps: {
include: [
'react/jsx-dev-runtime',
]
},
};
} else if (process.env.BUILD_EXAMPLES) {
// Config to build static assets from examples
return {
...common,
build: {
...common.build,
chunkSizeWarningLimit: 2048,
},
};
} else {
// Config to build the library or locally develop it with examples
return {
...common,
plugins: [
cssInjectedByJsPlugin({
jsAssetsFilterFunction: outputChunk => outputChunk.fileName === 'workspace.js'
}),
],
build: {
...common.build,
lib: {
entry: {
'workspace': resolve(__dirname, './src/workspace'),
'forms': resolve(__dirname, './src/forms/index'),
'layout-sync': resolve(__dirname, './src/layout-sync'),
'legacy-styles': resolve(__dirname, './src/legacy-styles'),
'layout.worker': resolve(__dirname, './src/layout.worker'),
},
formats: ['es'],
},
rollupOptions: {
...common.build.rollupOptions,
input: command === 'serve'
? common.build.rollupOptions.input
: undefined,
external: [
'@reactodia/hashmap',
'@reactodia/worker-proxy',
'@reactodia/worker-proxy/protocol',
'clsx',
'd3-color',
'file-saver',
'n3',
'react',
'react/jsx-runtime',
'react-dom',
],
},
minify: false,
cssMinify: true,
sourcemap: true,
},
define: command === 'serve' ? common.define : undefined,
server: {
port: 10555,
proxy: {
'/sparql': {
target: process.env.SPARQL_ENDPOINT ?? '/sparql',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/sparql/, ''),
},
'/wikidata': {
target: process.env.WIKIDATA_ENDPOINT ?? '/wikidata',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/wikidata/, ''),
},
}
},
};
}
});