-
-
Notifications
You must be signed in to change notification settings - Fork 289
/
vite.base.config.ts
79 lines (77 loc) · 2.13 KB
/
vite.base.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import {UserConfig, defineConfig} from "vite";
import {nodePolyfills} from "vite-plugin-node-polyfills";
import {visualizer} from "rollup-plugin-visualizer";
import topLevelAwait from "vite-plugin-top-level-await";
import {blsBrowserPlugin} from "./scripts/vite/plugins/blsBrowserPlugin.js";
export function getBaseViteConfig(
pkgInfo: {
description: string;
version: string;
author: string;
license: string;
homepage: string;
},
{entry, libName}: {entry: string; libName: string}
): UserConfig {
// TODO: Investigate why this banner is not appended to the build header.
const banner =
`/* ${pkgInfo.description}\n` +
" * \n" +
` * Version: ${pkgInfo.version}\n` +
` * Author: ${pkgInfo.author}\n` +
` * License: ${pkgInfo.license}\n` +
` * Web: ${pkgInfo.homepage}\n` +
"*/";
return defineConfig({
plugins: [
topLevelAwait(),
blsBrowserPlugin(),
nodePolyfills({
include: ["http", "https", "stream"],
globals: {Buffer: true, process: true},
protocolImports: true,
}),
...(process.env.DEBUG_BUNDLE ? [visualizer()] : []),
],
mode: "production",
appType: "custom",
esbuild: {
banner,
legalComments: "none",
sourcemap: "inline",
},
build: {
// "modules" refer to ['es2020', 'edge88', 'firefox78', 'chrome87', 'safari14']
target: "modules",
outDir: "dist",
sourcemap: true,
minify: true,
manifest: "manifest.json",
ssr: false,
ssrManifest: false,
emptyOutDir: true,
lib: {
entry,
formats: ["es"],
name: libName,
fileName: (format) => {
if (format === "esm" || format === "es") {
return `${libName.toLowerCase()}.min.mjs`;
} else if (format === "cjs") {
return `${libName.toLowerCase()}.min.cjs`;
} else {
return `${libName.toLowerCase()}.min.${format}.js`;
}
},
},
rollupOptions: {
output: {
inlineDynamicImports: true,
},
treeshake: {
preset: "recommended",
},
},
},
});
}