-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.mts
45 lines (42 loc) · 909 Bytes
/
vite.config.mts
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
import { defineConfig, Plugin } from "vite"
import fs from "node:fs"
/**
* Replace script tag of "index.html"
*/
function transformIndex(file: string) {
const plugin: Plugin = {
name: "transformIndex",
async buildStart() {
this.addWatchFile(file)
},
async buildEnd() {
this.emitFile({
type: "asset",
fileName: file,
source: fs
.readFileSync(file)
.toString()
.replace(
`<script type="module" src="/src/main.ts"></script>`,
`<script src="jian-doc.umd.js"></script>`
)
})
}
}
return plugin
}
export default defineConfig({
appType: "mpa",
build: {
lib: {
name: "jiandoc",
entry: "src/main.ts",
formats: ["umd"]
},
cssCodeSplit: true,
rollupOptions: {
input: "index.html",
plugins: [transformIndex("index.html")]
}
}
})