-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
53 lines (48 loc) · 1.17 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
import { defineConfig, loadEnv } from "vite";
import path from "path";
import packageJson from "./package.json";
const { resolve } = path;
/**
* https://vitejs.dev/config/
* @type { import('vite').UserConfig }
*/
export default defineConfig(({ mode }) => {
const envDir = "./env";
const envPrefix = ["VITE", "APP"];
// Env var
const { APP_NAME, APP_BASE_URL } = loadEnv(mode, envDir, envPrefix);
// Build files name
const packageName = packageJson.name;
const buildFileName = {
es: `${packageName}.mjs`,
cjs: `${packageName}.cjs`,
umd: `${packageName}.umd.js`,
iife: `${packageName}.iife.js`,
};
return {
envDir,
envPrefix,
base: APP_BASE_URL,
resolve: {
alias: {
"@/*": resolve(__dirname, "src"),
},
},
server: {
port: 3000,
},
build: {
lib: {
entry: path.resolve(__dirname, "src/app.ts"),
name: APP_NAME,
formats: ["es", "cjs", "umd", "iife"],
fileName: (format) => buildFileName[format],
},
rollupOptions: {
output: { assetFileNames: `${packageName}.[ext]` },
},
emptyOutDir: true,
assetsDir: "assets",
},
};
});