-
Notifications
You must be signed in to change notification settings - Fork 3
/
vite.config.js
62 lines (53 loc) · 1.38 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
50
51
52
53
54
55
56
57
58
59
60
61
62
import path from "path";
import fs from "fs";
const ignorePaths = [".git", "node_modules", "dist", "site"];
function getHtmlPaths(dirPath = __dirname, htmlPaths = {}) {
const files = fs.readdirSync(dirPath);
for (const file of files) {
if (ignorePaths.includes(file)) {
continue;
}
const absPath = path.join(dirPath, file);
if (fs.statSync(absPath).isDirectory()) {
htmlPaths = getHtmlPaths(absPath, htmlPaths);
} else if (path.extname(file) === ".html") {
const relPath = path.relative(__dirname, absPath);
htmlPaths[relPath] = absPath;
}
}
return htmlPaths;
}
export default ({ command, mode }) => {
if (mode === "site" || command === "serve") {
let base = "/";
const repo = process.env.GITHUB_REPOSITORY;
if (repo) {
base = `/${repo.split("/")[1]}/`;
}
return {
base,
build: {
outDir: path.resolve(__dirname, "site"),
minify: false,
rollupOptions: {
input: getHtmlPaths(),
},
},
publicDir: path.join(__dirname, "examples", "public"),
};
} else {
return {
build: {
lib: {
entry: path.resolve(__dirname, "src/three-omi.ts"),
name: "OMI",
formats: ["es", "cjs"],
},
minify: false,
rollupOptions: {
external: ["three", /^three\//],
}
},
};
}
};