generated from hywax/vite-vanilla-library-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
66 lines (60 loc) · 1.41 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
import { resolve } from "node:path";
import { defineConfig } from "vite";
import dts from "vite-plugin-dts";
import packageJson from "./package.json";
import { InlineConfig } from "vitest";
import type { InputOption } from "rollup";
declare module "vite" {
interface UserConfig {
test?: InlineConfig;
}
}
const testRuntime = process.env.TEST_RUNTIME || "node";
console.log("testRuntime", testRuntime);
let testConfig: InlineConfig = {};
if (testRuntime === "node") {
testConfig = {
environment: "node",
coverage: {
provider: "v8",
exclude: ["typedoc.cjs", "site"],
},
};
}
// Not edge the browser, serverless edge computing runtime
if (testRuntime === "edge") {
testConfig = {
environment: "edge-runtime",
};
}
if (["chrome", "firefox", "safari"].includes(testRuntime)) {
testConfig = {
browser: {
provider: "webdriverio",
name: testRuntime,
enabled: true,
},
};
}
const entry: InputOption = Object.fromEntries([
...Object.values(packageJson.exports).map(
(e) =>
[
e.import.replace(/^[.]\/dist\//, "").replace(/[.]js$/, ""),
resolve(
__dirname,
e.import.replace(/^[.]\/dist/, "./src").replace(/[.]js$/, ".ts")
),
] as const
),
]);
export default defineConfig({
build: {
lib: {
entry,
formats: ["es", "cjs"],
},
},
plugins: [dts({ rollupTypes: true })],
test: testConfig,
});