-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
73 lines (68 loc) · 1.8 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import * as path from "path";
import { defineConfig } from "vite";
import banner from "vite-plugin-banner";
import styleInject from "./plugins/style-inject";
import packageJson from "./package.json";
const packageName = packageJson.name;
const outputName = "popover";
const getPascalCaseName = () => {
try {
return packageName
.replace(new RegExp(/[-_]+/, "g"), " ")
.replace(new RegExp(/[^\w\s]/, "g"), "")
.replace(
new RegExp(/\s+(.)(\w+)/, "g"),
($1, $2, $3) => `${$2.toUpperCase() + $3.toLowerCase()}`,
)
.replace(new RegExp(/\s/, "g"), "")
.replace(new RegExp(/\w/), (s) => s.toUpperCase());
} catch (err) {
throw new Error("Name property in package.json is missing.");
}
};
const fileName = {
es: `${outputName}.es.js`,
umd: `${outputName}.umd.js`,
iife: `${outputName}.iife.js`,
};
const pkgInfo = `/**
* name: ${packageJson.name}
* version: ${packageJson.version}
* description: ${packageJson.description}
* author: ${packageJson.author}
* homepage: ${packageJson.homepage}
* repository: ${packageJson.repository.url}
*/`;
export default defineConfig(({ command, mode }) => {
return {
base: "./",
server: {
port: 8080,
https: false,
open: true,
hmr: {
overlay: false,
},
},
build: {
lib: {
entry: path.resolve(__dirname, "src/index.ts"),
name: getPascalCaseName(),
formats: ["es", "umd", "iife"],
fileName: (format) => fileName[format],
},
rollupOptions: {
output: {
exports: "named",
},
},
copyPublicDir: false,
},
plugins: [banner(pkgInfo), styleInject({ styleId: "next-popover-style" })],
resolve: {
alias: {
"@/*": path.resolve(__dirname, "src"),
},
},
};
});