-
Notifications
You must be signed in to change notification settings - Fork 97
/
vite.config.ts
57 lines (55 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
import react from "@vitejs/plugin-react-swc";
import path from "node:path";
import { defineConfig } from "vite";
import Spritesmith from "vite-plugin-spritesmith";
// https://vitejs.dev/config/
export default defineConfig(({ command }) => {
return {
base: "",
plugins: [
react(),
buildAtlas("rome", command === "serve"),
buildAtlas("person", command === "serve"),
buildAtlas("building", command === "serve"),
buildAtlas("tile", command === "serve"),
buildAtlas("flag", command === "serve"),
buildAtlas("misc", command === "serve"),
],
server: {
port: 3000,
host: true,
},
build: {
sourcemap: true,
target: "es2015",
},
test: {
browser: {
enabled: true,
headless: true,
name: "chrome",
},
},
};
});
function buildAtlas(folder: string, watch: boolean) {
return Spritesmith({
watch: watch,
src: {
cwd: `./src/textures/${folder}`,
glob: "*.png",
},
apiOptions: {
generateSpriteName: (filePath: string) => {
return `${folder.charAt(0).toUpperCase()}${folder.slice(1)}_${path.basename(filePath, ".png")}`;
},
},
target: {
image: `./src/images/textures_${folder}.png`,
css: [[`./src/images/textures_${folder}.json`, { format: "json_texture" }]],
},
spritesmithOptions: {
padding: 1,
},
});
}