forked from mdbootstrap/TW-Elements
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.js
55 lines (53 loc) · 1.53 KB
/
vite.config.js
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
import { defineConfig } from "vite";
import { resolve } from "path";
import glob from "glob";
import path from "node:path";
import { fileURLToPath } from "node:url";
const distName = process.env.mode === "demo" ? "./dist-demo" : "./dist";
// https://vitejs.dev/config/
export default defineConfig({
base: "./",
define: {
// for popper to not crash in docs
"process.env": {},
initiatedComponents: [],
},
build: {
outDir: distName,
emptyOutDir: process.env.buildFile ? false : true,
lib: process.env.mode !== "demo" && {
entry: resolve(
__dirname,
`src/js/index.${process.env.buildFile === "umd" ? "umd" : "es"}.js`
),
formats: process.env.buildFile ? ["umd"] : ["es"],
name: "te",
fileName: (format) => `tw-elements.${format}.min.js`,
},
rollupOptions: {
input: process.env.mode === "demo" && {
index: "index.html",
...Object.fromEntries(
glob
.sync("demo/**/*.html")
.map((file) => [
path.relative(
"demo",
file.slice(0, file.length - path.extname(file).length)
),
fileURLToPath(new URL(file, import.meta.url)),
])
),
},
output: {
dir: "dist/js",
chunkFileNames: ({ name }) => {
const omitPhrase = [".umd", ".esm", ".es"];
omitPhrase.forEach((omit) => (name = name.replace(omit, "")));
return `${name}.[format].js`;
},
},
},
sourcemap: true,
},
});