-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathvite.config.ts
More file actions
40 lines (36 loc) · 1005 Bytes
/
Copy pathvite.config.ts
File metadata and controls
40 lines (36 loc) · 1005 Bytes
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
import { readFileSync } from "node:fs";
import path from "node:path";
import glob from "fast-glob";
import { defineConfig } from "vite";
const pkg = JSON.parse(readFileSync("./package.json", "utf-8"));
const externals = [
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.peerDependencies || {}),
];
const external = (id: string) =>
externals.some((pkg) => id === pkg || id.startsWith(`${pkg}/`));
const input = Object.fromEntries(
glob.sync("src/**/*.{ts,tsx}", { ignore: ["**/*.test.*"] }).map((file) => {
const name = file.replace(/^src\//, "").replace(/\.(ts|tsx)$/, "");
return [name, path.resolve(__dirname, file)];
}),
);
export default defineConfig({
build: {
target: "esnext",
outDir: "dist",
lib: false,
rollupOptions: {
input,
output: {
entryFileNames: "[name].js",
chunkFileNames: "[name]-[hash].js",
format: "es",
preserveModules: true,
preserveModulesRoot: "src",
},
external,
preserveEntrySignatures: "strict",
},
},
});