-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.mts
44 lines (40 loc) · 1000 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
import { defineConfig, type Plugin, type ResolvedConfig } from "vite"
import { AssetPack, AssetPackConfig } from "@assetpack/core"
import { texturePacker } from "@assetpack/core/texture-packer"
function assetpackPlugin(): Plugin {
const apConfig: AssetPackConfig = {
entry: "./assets",
output: "./public/assets",
pipes: [
texturePacker({
resolutionOptions: { template: "", resolutions: { default: 1 } },
}),
],
}
let mode: ResolvedConfig["command"]
let ap: AssetPack | undefined
return {
name: "vite-plugin-assetpack",
buildStart: async () => {
if (mode === "serve") {
if (ap) return
ap = new AssetPack(apConfig)
void ap.watch()
} else {
await new AssetPack(apConfig).run()
}
},
buildEnd: async () => {
if (ap) {
await ap.stop()
ap = undefined
}
},
}
}
export default defineConfig({
server: {
hmr: true,
},
plugins: [assetpackPlugin()],
})