-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
127 lines (120 loc) · 2.63 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
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
/// <reference types="vitest/globals" />
import { resolve } from "node:path";
import type { RollupOptions } from "rollup";
import { InlineConfig } from "vitest";
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react-swc";
import dts from "vite-plugin-dts";
import IstanbulPlugin from "vite-plugin-istanbul";
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",
"@feedzai/js-utilities": "JSUtilities",
"focus-trap-react": "FocusTrapReact",
};
const ROLLUP_OPTIONS: RollupOptions = {
external: [...Object.keys(BASE_EXTERNAL_LIBRARIES)],
output: {
globals: {
...BASE_EXTERNAL_LIBRARIES,
},
},
};
/**
* Gets a per-file format filename.
*
* @param format
* @returns
*/
function getFilename(format: ModuleFormat) {
const OUTPUT: Partial<Record<typeof format, string>> = {
es: `index.mjs`,
cjs: `index.cjs`,
};
return OUTPUT[format] ?? `index.cjs`;
}
const VITEST_CONFIG: InlineConfig = {
globals: true,
environment: "jsdom",
include: ["./test/vitest/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"],
setupFiles: "./config/setupVitest.ts",
coverage: {
all: true,
enabled: true,
reporter: ["html", "json", "text-summary"],
provider: "istanbul",
reportsDirectory: "./coverage-reports/vitest",
exclude: [
"coverage/**",
"dist/**",
"**/[.]**",
"packages/*/test?(s)/**",
"**/*.d.ts",
"**/virtual:*",
"**/__x00__*",
"**/\x00*",
"test/cypress/**",
"test?(s)/**",
"test?(-*).?(c|m)[jt]s?(x)",
"**/*{.,-}{test,spec}.?(c|m)[jt]s?(x)",
"**/__tests__/**",
"**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build}.config.*",
"**/vitest.{workspace,projects}.[jt]s?(on)",
"**/.{eslint,mocha,prettier}rc.{?(c|m)js,yml}",
"documentation/**",
"coverage-reports/**",
"coverage/**",
],
},
};
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
dts({
insertTypesEntry: true,
}),
IstanbulPlugin({
cypress: true,
requireEnv: false,
}),
tsconfigPaths(),
react(),
],
resolve: {
alias: [
{
find: "src",
replacement: resolve(__dirname, "./src"),
},
],
},
css: {
modules: {
generateScopedName: "fdz-css-[hash:base64:8]",
},
},
build: {
minify: true,
lib: {
entry: resolve(__dirname, "src/index.ts"),
name: "ReactA11yTools",
formats: ["es", "cjs"],
fileName: getFilename,
},
rollupOptions: ROLLUP_OPTIONS,
},
test: VITEST_CONFIG,
});