-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
84 lines (83 loc) · 1.97 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
import { defineConfig } from "vite"
import typescript from "@rollup/plugin-typescript"
import path from "path"
import { typescriptPaths } from "rollup-plugin-typescript-paths"
import react from "@vitejs/plugin-react"
export default defineConfig(({ mode }) => {
// build the bridge.js library
if (mode === "library") {
return {
plugins: [],
resolve: {
alias: [
{
find: "~",
replacement: path.resolve(__dirname, "./src"),
},
],
},
server: {
port: 5179,
},
build: {
manifest: true,
minify: true,
reportCompressedSize: true,
lib: {
entry: path.resolve(process.cwd(), "src/library/index.ts"),
name: "@lookingglass/bridge.js",
fileName: "looking-glass-bridge",
formats: ["es", "cjs"],
},
rollupOptions: {
external: [],
plugins: [
typescriptPaths({
preserveExtensions: true,
}),
typescript({
tsconfig: path.resolve(__dirname, "src/library/tsconfig.json"),
sourceMap: false,
declaration: true,
outDir: path.resolve(__dirname, "dist"),
}),
],
},
},
}
} else if (mode === "react") {
// get the current git commit so we can view/link to the source code
const commitHash = require("child_process").execSync("git rev-parse --short HEAD").toString()
console.log("commit hash:", commitHash)
return {
build: {
outDir: "app",
},
plugins: [react()],
resolve: {
alias: {
"@library": path.resolve(__dirname, "./src/library"),
},
},
define: {
__COMMIT_HASH__: JSON.stringify(commitHash),
},
rollupOptions: {
external: [],
plugins: [
typescriptPaths({
preserveExtensions: true,
}),
typescript({
tsconfig: path.resolve(__dirname, "src/react-app/tsconfig.json"),
sourceMap: false,
declaration: true,
outDir: "app",
}),
],
},
}
} else {
throw new Error("Invalid mode. Please ensure the package.json file is configured properly")
}
})