-
-
Notifications
You must be signed in to change notification settings - Fork 46
/
vite.config.js
76 lines (59 loc) · 2.24 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import path from "path";
import fs from "fs";
import { directoryPlugin } from 'vite-plugin-list-directory-contents';
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" ){
const repo = process.env.GITHUB_REPOSITORY;
const base = ( repo )? `/${repo.split("/")[1]}/` : '/';
return {
base,
build : {
outDir : path.resolve( __dirname, "site" ),
minify : false,
rollupOptions : { input: getHtmlPaths() },
},
publicDir : path.join( __dirname, "examples", "public" ),
plugins : [
directoryPlugin( {
baseDir : __dirname,
filterList : [ 'node_modules', '.git', '.github', '_store', '_images', 'dist', 'src', '.*' ],
})
],
server : {
port : 3009,
open : '/',
},
};
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
} else {
return {
build: {
minify : false,
lib : {
entry : path.resolve( __dirname, "src/ossos.ts" ),
name : "ossos",
formats : [ "es", "cjs" ],
},
rollupOptions : {
external : [ "three", /^three\// ],
}
},
};
}
};