-
Notifications
You must be signed in to change notification settings - Fork 1
/
vite.config.ts
99 lines (92 loc) · 1.96 KB
/
vite.config.ts
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
/**
* Please refer to the terms of the license agreement in the root of the project
*
* (c) 2024 Feedzai
*/
import type { UserConfig } from "vite";
import type { RollupOptions } from "rollup";
import { resolve } from "path";
import { defineConfig } from "vite";
import dts from "vite-plugin-dts";
import istanbul from "vite-plugin-istanbul";
import react from "@vitejs/plugin-react-swc";
import tsconfigPaths from "vite-tsconfig-paths";
type ModuleFormat =
| "amd"
| "cjs"
| "es"
| "iife"
| "system"
| "umd"
| "commonjs"
| "esm"
| "module"
| "systemjs";
const BASE_EXTERNAL_LIBRARIES = {
react: "React",
"react-dom": "ReactDOM",
"react/jsx-runtime": "react/jsx-runtime",
};
const ROLLUP_OPTIONS: RollupOptions = {
external: [...Object.keys(BASE_EXTERNAL_LIBRARIES)],
output: {
preserveModules: true,
inlineDynamicImports: false,
globals: {
...BASE_EXTERNAL_LIBRARIES,
},
},
};
/**
* Gets a per-file format filename.
*
* @param format
* @returns
*/
function getFilename(format: ModuleFormat, entryName: string) {
const OUTPUT: Partial<Record<typeof format, string>> = {
es: `${entryName}.mjs`,
cjs: `${entryName}.cjs`,
};
return OUTPUT[format] ?? `${entryName}.cjs`;
}
const CONFIG: UserConfig = {
plugins: [
react(),
istanbul({
cypress: true,
requireEnv: false,
}),
dts({
insertTypesEntry: false,
}),
tsconfigPaths(),
],
resolve: {
alias: [
{
find: "src",
replacement: resolve(__dirname, "./src"),
},
],
},
build: {
lib: {
entry: {
index: resolve(__dirname, "src/index.ts"),
hooks: resolve(__dirname, "src/hooks.ts"),
},
name: "JSUtilities",
formats: ["es", "cjs"],
fileName: getFilename,
},
terserOptions: {
format: {
comments: false,
},
},
rollupOptions: ROLLUP_OPTIONS,
},
};
// https://vitejs.dev/config/
export default defineConfig(CONFIG);