-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvite.config.ts
126 lines (119 loc) · 3.4 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
/*
* Copyright © 2023 Norman Fomferra
* Permissions are hereby granted under the terms of the MIT License:
* https://opensource.org/licenses/MIT.
*/
import { defineConfig } from "vitest/config";
import react from "@vitejs/plugin-react-swc";
import dts from "vite-plugin-dts";
import { resolve, join } from "node:path";
import { readdirSync, statSync } from "node:fs";
// noinspection JSUnusedGlobalSymbols
/**
* See https://vitejs.dev/config/
*/
export default defineConfig({
plugins: [
react(),
dts({
include: ["src/framework"],
exclude: ["src/**/*.test.*", "src/framework/test/**/*"],
}),
],
resolve: {
alias: {
"@": resolve(__dirname, "src/framework"),
},
},
publicDir: false,
build: {
lib: {
// This is also the default
formats: ["es", "cjs"],
// Could also be a dictionary or array of multiple entry points
entry: {
"contrib/index": resolve(__dirname, "src/framework/contrib/index.ts"),
"core/index": resolve(__dirname, "src/framework/core/index.ts"),
"react/index": resolve(__dirname, "src/framework/react/index.ts"),
"util/index": resolve(__dirname, "src/framework/util/index.ts"),
},
// Only used for formats "umd" and "iife"
name: "extendit",
// "[name]" will resolve to keys from "entry" object,
// the proper extensions will be added
fileName: "[name]",
},
rollupOptions: {
// make sure to externalize deps that shouldn't be bundled
// into the library
external: [
...listExcludedFiles(join(__dirname, "src")),
"ajv",
"react",
"react-dom",
"zustand",
],
output: {
// Provide global variables to use in the UMD build
// for externalized deps
globals: {
ajv: "Ajv",
react: "React",
"react-dom": "ReactDom",
zustand: "Zustand",
},
},
},
},
test: {
environment: "jsdom",
setupFiles: ["src/framework/test/setup.ts"],
coverage: {
provider: "v8",
reporter: ["text", "json", "html"],
include: ["src/framework/core", "src/framework/util"],
},
onConsoleLog: (/*_log: string, _type: "stdout" | "stderr"*/):
| false
| void => {
const logLevel = process.env.VITE_LOG_LEVEL;
if (!logLevel || logLevel === "OFF") {
return false;
}
},
},
});
function listExcludedFiles(dirPath: string): string[] {
const files: string[] = [];
const handleFile = (file: string) => files.push(file);
listAllFiles(dirPath, "", handleFile);
function isTestFile(path: string) {
return (
path.startsWith("demo/") ||
path.includes(".test.") ||
path.startsWith("test/")
);
}
const excludedFiles = files
.filter(isTestFile)
.map((file) => join(dirPath, file));
console.log(`Excluding ${excludedFiles.length} files.`);
//console.log("Excluded files:", excludedFiles);
return excludedFiles;
}
function listAllFiles(
rootPath: string,
relPath: string,
onFile: (file: string) => void
) {
const absPath = relPath !== "" ? `${rootPath}/${relPath}` : rootPath;
readdirSync(absPath).forEach((name) => {
const absEntry = `${absPath}/${name}`;
const relEntry = relPath !== "" ? `${relPath}/${name}` : name;
if (statSync(absEntry).isDirectory()) {
listAllFiles(rootPath, relEntry, onFile);
} else {
onFile(relEntry);
}
});
}