-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvite.config.ts
71 lines (63 loc) · 1.5 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
import * as path from "node:path";
import * as fs from "node:fs/promises";
import { defineConfig } from "vite";
import sdk from "vite-plugin-sdk";
import { minify } from "html-minifier-terser";
import { app } from "./docs/akte.app";
const MINIFY_HTML_OPTIONS = {
collapseBooleanAttributes: true,
collapseWhitespace: true,
keepClosingSlash: true,
minifyCSS: true,
removeComments: true,
removeRedundantAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
useShortDoctype: true,
};
export default defineConfig({
build: {
lib: {
entry: {
index: "./src/index.ts",
vite: "./src/vite/index.ts",
},
},
},
plugins: [
sdk(),
{
name: "akte:welcome",
async writeBundle(options) {
const match = app.lookup("/welcome");
let welcomePage = await app.render(match);
const docURL = "https://akte.js.org";
// Load assets from documentation
welcomePage = welcomePage.replace(
"</head>",
`<base href="${docURL}" /></head>`,
);
welcomePage = welcomePage.replaceAll(
`href="/assets`,
`href="${docURL}/assets`,
);
welcomePage = welcomePage.replace(
/(src="\/assets\/js\/\w+?)\.ts/g,
"$1.js",
);
welcomePage = await minify(welcomePage, MINIFY_HTML_OPTIONS);
await fs.writeFile(
path.resolve(options.dir || "dist", "akteWelcome.html"),
welcomePage,
"utf-8",
);
},
},
],
test: {
coverage: {
reporter: ["lcovonly", "text"],
},
setupFiles: ["./test/__setup__.ts"],
},
});