-
Notifications
You must be signed in to change notification settings - Fork 1
/
vite.config.ts
94 lines (91 loc) · 3.09 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import { defineConfig } from "vite"
import react from "@vitejs/plugin-react"
import dts from "vite-plugin-dts"
import fs from "node:fs/promises"
const entries: Record<string, string> = {
index: "src/index.ts",
"extensions/guides": "src/extensions/guides.tsx",
"extensions/commands": "src/extensions/commands.ts",
"extensions/cursor": "src/extensions/cursor.ts",
"extensions/match-brackets/index": "src/extensions/match-brackets/index.ts",
"extensions/match-brackets/highlight": "src/extensions/match-brackets/highlight.ts",
"extensions/match-tags": "src/extensions/match-tags.ts",
"extensions/search/index": "src/extensions/search/index.ts",
search: "src/extensions/search/search.css",
invisibles: "src/extensions/search/invisibles.css",
copy: "src/extensions/copy-button/copy.css",
"extensions/copy-button/index": "src/extensions/copy-button/index.ts",
"extensions/folding/index": "src/extensions/folding/index.ts",
"extensions/autocomplete/index": "src/extensions/autocomplete/index.ts",
"extensions/autocomplete/css/index": "src/extensions/autocomplete/css/index.ts",
"extensions/autocomplete/markup/index": "src/extensions/autocomplete/markup/index.ts",
"extensions/autocomplete/javascript/index": "src/extensions/autocomplete/javascript/index.ts",
autocomplete: "src/extensions/autocomplete/style.css",
"autocomplete-icons": "src/extensions/autocomplete/icons.css",
"extensions/overscroll": "src/extensions/overscroll.ts",
folding: "src/extensions/folding/folding.css",
setups: "src/setups.tsx",
tooltips: "src/tooltips.ts",
scrollbar: "src/scrollbar.css",
"rtl-layout": "src/rtl-layout.css",
layout: "src/layout.css",
"themes/index": "src/themes/index.ts",
"utils/index": "src/utils/index.ts",
"prism/index": "src/prism/index.js",
"prism/utils": "src/prism/utils.js",
}
await Promise.all([
fs.readdir(new URL("./src/prism/languages", import.meta.url)).then(files =>
files.forEach(name => {
entries["prism/languages/" + name.slice(0, -3)] = "src/prism/languages/" + name
}),
),
fs.readdir(new URL("./src/themes", import.meta.url)).then(files =>
files.forEach(name => {
if (name.slice(-4) == ".css") {
entries["themes/" + name.slice(0, -4)] = "src/themes/" + name
}
}),
),
fs.readdir(new URL("./src/languages", import.meta.url)).then(files =>
files.forEach(name => {
if (name.slice(-3) == ".ts") {
entries["languages/" + name.slice(0, -3)] = "src/languages/" + name
}
}),
),
])
export default defineConfig({
plugins: [
react(),
dts({
beforeWriteFile(filePath) {
if (filePath.includes("languages/shared")) {
return false
}
},
}),
],
build: {
cssCodeSplit: true,
sourcemap: true,
cssMinify: "esbuild",
minify: false,
rollupOptions: {
external: ["react", "react-dom", "react/jsx-runtime"],
output: {
banner({ fileName, isEntry }) {
if (!isEntry && fileName.slice(0, 4) != "core") return ""
if (fileName.slice(0, 5) == "prism") return ""
if (fileName.slice(0, 5) == "theme") return ""
return '"use client";'
},
},
},
lib: {
entry: entries,
formats: ["es"],
},
target: ["es2021", "safari14"],
},
})