-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvite.config.ts
44 lines (38 loc) · 1.2 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
import { defineConfig } from "vite";
import { svelte } from "@sveltejs/vite-plugin-svelte";
import { config as configDotenv } from "dotenv";
import { resolve } from "path";
// infer which code we are building. We can choose between app, background and popup
const buildScript = process.env.npm_lifecycle_event || "";
const app = buildScript.includes(":") ? buildScript.split(":")[1] : "app";
// if building background, treat it as a library, not a web app
const isLibrary = app === "background";
const buildConfig = {
rootHtml: `./${app}.html`,
entryFileLib: `.src/${app}/${app}.ts`,
entryFileNames: `${app}/${app}.js`,
assetFileNames: `${app}/${app}.[ext]`,
};
// load variables from .env
configDotenv();
export default defineConfig({
plugins: [
// Only use svelte if not a library
!isLibrary && svelte(),
],
build: {
lib: isLibrary && {
entry: resolve(__dirname, buildConfig.entryFileLib),
name: app,
},
rollupOptions: {
input: { app: buildConfig.rootHtml },
output: {
entryFileNames: buildConfig.entryFileNames,
assetFileNames: buildConfig.assetFileNames,
},
},
emptyOutDir: false,
},
server: { open: buildConfig.rootHtml },
});