-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathvite.config.ts
More file actions
92 lines (84 loc) · 2.34 KB
/
vite.config.ts
File metadata and controls
92 lines (84 loc) · 2.34 KB
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
import {
js13kViteConfig,
defaultViteBuildOptions,
RoadrollerOptions,
defaultRollupOptions,
defaultTerserOptions,
} from "js13k-vite-plugins";
import { defineConfig, ConfigEnv, UserConfig } from "vite";
import { ViteMinifyPlugin } from "vite-plugin-minify";
import glsl from "vite-plugin-glsl";
import { zig } from "./vite-zig";
const createProdConfig = (): ConfigEnv => {
defaultViteBuildOptions.assetsInlineLimit = 0;
defaultViteBuildOptions.modulePreload = false;
defaultViteBuildOptions.assetsDir = "";
defaultTerserOptions.mangle = {
properties: {
regex: /^_[a-z]/,
},
};
const js13kConfig: ConfigEnv = js13kViteConfig({
roadrollerOptions: false,
viteOptions: defaultViteBuildOptions,
terserOptions: defaultTerserOptions,
}) as ConfigEnv;
(js13kConfig as any).rollupConfig = defaultRollupOptions;
(js13kConfig as any).rollupConfig.output = {
assetFileNames: "[name].[ext]",
entryFileNames: "i.js",
chunkFileNames: "[name].[ext]",
};
(js13kConfig as any).base = "";
// (js13kConfig as any).server = { port: 8080, open: true };
(js13kConfig as any).plugins.push(
glsl({
compress: true,
}),
zig(),
ViteMinifyPlugin({
includeAutoGeneratedTags: true,
removeAttributeQuotes: true,
removeComments: true,
removeRedundantAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
sortClassName: true,
useShortDoctype: true,
collapseWhitespace: true,
collapseInlineTagWhitespace: true,
removeEmptyAttributes: true,
removeOptionalTags: true,
sortAttributes: true,
}),
{
name: "final-transformations",
enforce: "post",
renderChunk: async (code: string) => {
return {
code: code.replaceAll("const ", "let "),
map: null,
};
},
transformIndexHtml(html: string) {
const regex = /<script crossorigin (.*?)/gi;
const replacement = '<script $1';
return html.replace(regex, replacement);
},
}
);
return js13kConfig;
};
export default defineConfig((env: ConfigEnv): UserConfig => {
if(env.command == "serve") {
return {
base: "",
// server: { port: 8080, open: true },
plugins: [
glsl(),
zig(),
],
};
}
return createProdConfig();
});