-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.js
49 lines (46 loc) · 1.27 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
// @ts-check
import "dotenv/config";
import { defineConfig } from "vite";
import dts from "vite-plugin-dts";
import { dirname, resolve } from "node:path";
import { fileURLToPath } from "node:url";
import { readdir } from "node:fs/promises";
// Credit https://stackoverflow.com/a/24594123
const getDirectories = async (source) =>
(await readdir(source, { withFileTypes: true }))
.filter((dirent) => dirent.isDirectory())
.map((dirent) => dirent.name);
const __dirname = dirname(fileURLToPath(import.meta.url));
const buildSiteMode = process.env.BUILD_SITE_NOT_LIBRARY === "yes";
console.info("Build site mode:", buildSiteMode);
export default defineConfig({
plugins: [!buildSiteMode && dts()],
optimizeDeps: {
// This makes the examples work
include: ["examples/**/*"],
},
build: {
rollupOptions: buildSiteMode
? {
input: {
...Object.fromEntries(
(
await getDirectories(
resolve(__dirname, "examples"),
)
).map((dir) => [dir, `examples/${dir}/index.html`]),
),
"examples-home": "examples/index.html",
},
}
: undefined,
lib: buildSiteMode
? undefined
: {
entry: resolve(__dirname, "src/index.ts"),
name: "TimeLine",
fileName: "TimeLine",
formats: ["es", "umd"],
},
},
});