Skip to content

Commit

Permalink
Implement map optimization by the .env
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexis Faizeau committed Sep 28, 2023
1 parent e77dd04 commit 5943534
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 11 deletions.
9 changes: 9 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

# Log level (0 = none, 1 = info, 2 = verbose)
LOG_LEVEL=1

# Tileset optimization
TILESET_OPTIMIZATION=false
# Tileset optimization quality (0.0 - 1.0)
TILESET_OPTIMIZATION_QUALITY_MIN=0.9
TILESET_OPTIMIZATION_QUALITY_MAX=1.0
33 changes: 26 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "workadventure-map-starter-kit",
"version": "3.3.6",
"version": "3.3.7",
"license": "MIT",
"scripts": {
"dev": "vite",
Expand All @@ -11,9 +11,10 @@
"devDependencies": {
"@types/node": "^18.15.11",
"@workadventure/iframe-api-typings": "^1.17.1",
"dotenv": "^16.3.1",
"typescript": "^4.9.5",
"vite": "^4.3.9",
"wa-map-optimizer-vite": "^1.1.17"
"wa-map-optimizer-vite": "^1.1.18"
},
"dependencies": {
"@workadventure/scripting-api-extra": "^1.4.8"
Expand Down
22 changes: 20 additions & 2 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
import 'dotenv/config';
import { defineConfig } from "vite";
import { getMaps, getMapsOptimizers, getMapsScripts } from "wa-map-optimizer-vite";
import { getMaps, getMapsOptimizers, getMapsScripts, LogLevel, OptimizeOptions } from "wa-map-optimizer-vite";

const maps = getMaps();

let optimizerOptions: OptimizeOptions = {
logs: process.env.LOG_LEVEL && process.env.LOG_LEVEL in LogLevel ? LogLevel[process.env.LOG_LEVEL] : LogLevel.NORMAL,
};

if (process.env.TILESET_OPTIMIZATION && process.env.TILESET_OPTIMIZATION === "true") {
const qualityMin = process.env.TILESET_OPTIMIZATION_QUALITY_MIN ? parseInt(process.env.TILESET_OPTIMIZATION_QUALITY_MIN) : 0.9;
const qualityMax = process.env.TILESET_OPTIMIZATION_QUALITY_MAX ? parseInt(process.env.TILESET_OPTIMIZATION_QUALITY_MAX) : 1;

optimizerOptions.output = {
tileset: {
compress: {
quality: [qualityMin, qualityMax],
}
}
}
}

export default defineConfig({
base: "./",
build: {
Expand All @@ -13,7 +31,7 @@ export default defineConfig({
},
},
},
plugins: [...getMapsOptimizers(maps)],
plugins: [...getMapsOptimizers(maps, optimizerOptions)],
server: {
host: "localhost",
headers: {
Expand Down

0 comments on commit 5943534

Please sign in to comment.