-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
vite.config.ts
47 lines (42 loc) · 1.47 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
import { defineConfig } from "vite";
import pkg from "./package.json";
import { qwikVite } from "@builder.io/qwik/optimizer";
import tsconfigPaths from "vite-tsconfig-paths";
const { dependencies = {}, peerDependencies = {} } = pkg as any;
const makeRegex = (dep) => new RegExp(`^${dep}(/.*)?$`);
const excludeAll = (obj) => Object.keys(obj).map(makeRegex);
export default defineConfig(({ command }) => {
const env = process.env.ENTRY as "styled" | "headless" | undefined;
if (!env && command === "build") throw new Error("ENTRY env var is required");
const entry =
env === "headless" ? "src/lib/headless/toast-wrapper.tsx" : "src/lib";
return {
build: {
target: "es2020",
outDir: "lib",
lib: {
entry,
formats: ["es", "cjs"],
fileName: (format, file) => {
const ext = format === "es" ? "mjs" : "cjs";
const name = env === "styled" ? "index" : "headless";
return `${name}.qwik.${ext}`;
},
},
emptyOutDir: env === "styled" ? true : false,
rollupOptions: {
// externalize deps that shouldn't be bundled into the library
external: [
/^node:.*/,
...excludeAll(dependencies),
...excludeAll(peerDependencies),
],
// all the chunks created by vite shuold also have qwik in the name
output: {
chunkFileNames: "[name]-[format].qwik.js",
},
},
},
plugins: [qwikVite(), tsconfigPaths()],
};
});