Skip to content

Commit 5943534

Browse files
author
Alexis Faizeau
committed
Implement map optimization by the .env
1 parent e77dd04 commit 5943534

File tree

4 files changed

+58
-11
lines changed

4 files changed

+58
-11
lines changed

.env

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
# Log level (0 = none, 1 = info, 2 = verbose)
3+
LOG_LEVEL=1
4+
5+
# Tileset optimization
6+
TILESET_OPTIMIZATION=false
7+
# Tileset optimization quality (0.0 - 1.0)
8+
TILESET_OPTIMIZATION_QUALITY_MIN=0.9
9+
TILESET_OPTIMIZATION_QUALITY_MAX=1.0

package-lock.json

Lines changed: 26 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "workadventure-map-starter-kit",
3-
"version": "3.3.6",
3+
"version": "3.3.7",
44
"license": "MIT",
55
"scripts": {
66
"dev": "vite",
@@ -11,9 +11,10 @@
1111
"devDependencies": {
1212
"@types/node": "^18.15.11",
1313
"@workadventure/iframe-api-typings": "^1.17.1",
14+
"dotenv": "^16.3.1",
1415
"typescript": "^4.9.5",
1516
"vite": "^4.3.9",
16-
"wa-map-optimizer-vite": "^1.1.17"
17+
"wa-map-optimizer-vite": "^1.1.18"
1718
},
1819
"dependencies": {
1920
"@workadventure/scripting-api-extra": "^1.4.8"

vite.config.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,26 @@
1+
import 'dotenv/config';
12
import { defineConfig } from "vite";
2-
import { getMaps, getMapsOptimizers, getMapsScripts } from "wa-map-optimizer-vite";
3+
import { getMaps, getMapsOptimizers, getMapsScripts, LogLevel, OptimizeOptions } from "wa-map-optimizer-vite";
34

45
const maps = getMaps();
56

7+
let optimizerOptions: OptimizeOptions = {
8+
logs: process.env.LOG_LEVEL && process.env.LOG_LEVEL in LogLevel ? LogLevel[process.env.LOG_LEVEL] : LogLevel.NORMAL,
9+
};
10+
11+
if (process.env.TILESET_OPTIMIZATION && process.env.TILESET_OPTIMIZATION === "true") {
12+
const qualityMin = process.env.TILESET_OPTIMIZATION_QUALITY_MIN ? parseInt(process.env.TILESET_OPTIMIZATION_QUALITY_MIN) : 0.9;
13+
const qualityMax = process.env.TILESET_OPTIMIZATION_QUALITY_MAX ? parseInt(process.env.TILESET_OPTIMIZATION_QUALITY_MAX) : 1;
14+
15+
optimizerOptions.output = {
16+
tileset: {
17+
compress: {
18+
quality: [qualityMin, qualityMax],
19+
}
20+
}
21+
}
22+
}
23+
624
export default defineConfig({
725
base: "./",
826
build: {
@@ -13,7 +31,7 @@ export default defineConfig({
1331
},
1432
},
1533
},
16-
plugins: [...getMapsOptimizers(maps)],
34+
plugins: [...getMapsOptimizers(maps, optimizerOptions)],
1735
server: {
1836
host: "localhost",
1937
headers: {

0 commit comments

Comments
 (0)