-
Notifications
You must be signed in to change notification settings - Fork 1
/
vite.config.js
57 lines (49 loc) · 1.19 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
import { resolve } from "node:path";
import { transform } from "esbuild";
import { defineConfig } from "vite";
import { name } from "./package.json";
// minify plugin, based on esbuild's native method
const minifyEs = {
renderChunk: {
order: "post",
async handler(code, _, { format }) {
if (format === "es") return await transform(code, { minify: true });
return code;
},
},
};
// paths
const srcPath = resolve(__dirname, "./src");
const examplePath = resolve(__dirname, "./example");
const rootPath = resolve(__dirname, "./");
// config
export default defineConfig(({ command, mode }) => {
const config = {
plugins: [minifyEs],
resolve: {
alias: {
"@": srcPath,
},
},
build: {
emptyOutDir: true,
},
test: {
root: "./src",
environment: "jsdom",
},
};
if (command === "serve" || (command === "build" && mode === "example")) {
config.root = examplePath;
}
if (command === "build" && mode === "lib") {
config.root = rootPath;
config.build.lib = {
entry: srcPath,
formats: ["es", "umd"],
name,
fileName: (format) => `index.${format}.js`,
};
}
return config;
});