-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.js
67 lines (61 loc) · 2 KB
/
vite.config.js
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
import { defineConfig } from 'vite';
import { babel } from '@rollup/plugin-babel';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import copy from 'rollup-plugin-copy';
import fg from 'fast-glob';
/**
* Gets the entrypoints of files within a set of given paths (i.e src/tests).
* This is useful as when we execute k6, we run it against individual test files
* @returns an object of [fileName]: absolute file path
*/
const getEntryPoints = (entryPoints) => {
// Searches for files that match the patterns defined in the array of input points.
// Returns an array of absolute file paths.
const files = fg.sync(entryPoints, { absolute: true });
// Maps the file paths in the "files" array to an array of key-value pair.
const entities = files.map((file) => {
// Extract the part of the file path after the "src" folder and before the file extension.
const [key] = file.match(/(?<=src\/).*$/) || [];
// Remove the file extension from the key.
const keyWithoutExt = key.replace(/\.[^.]*$/, '');
return [keyWithoutExt, file];
});
// Convert the array of key-value pairs to an object using the Object.fromEntries() method.
// Returns an object where each key is the file name without the extension and the value is the absolute file path.
return Object.fromEntries(entities);
};
export default defineConfig({
mode: 'production',
build: {
lib: {
entry: getEntryPoints(['./src/tests/*.ts']),
fileName: '[name]',
formats: ['cjs'],
sourcemap: true,
},
outDir: 'dist',
minify: false, // Don't minimize, as it's not used in the browser
rollupOptions: {
external: [new RegExp(/^(k6|https?\:\/\/)(\/.*)?/)],
},
},
resolve: {
extensions: ['.ts', '.js'],
},
plugins: [
copy({
targets: [
{
src: 'assets/**/*',
dest: 'dist',
noErrorOnMissing: true,
},
],
}),
babel({
babelHelpers: 'bundled',
exclude: /node_modules/,
}),
nodeResolve(),
],
});