diff --git a/vite.config.ts b/vite.config.ts index 236e202..2a2759f 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,13 +1,31 @@ -import { defineConfig } from "vite"; +import 'dotenv/config'; import { lstatSync, readdirSync } from 'fs'; -import { getMaps, getMapsOptimizers, getMapsScripts } from "wa-map-optimizer-vite"; +import { defineConfig } from "vite"; +import { getMaps, getMapsOptimizers, getMapsScripts, LogLevel, OptimizeOptions } from "wa-map-optimizer-vite"; + +const isDirectory = (path: string) => { + const stats = lstatSync(path) + return stats.isDirectory() +} const maps = getMaps(); -const isDirectory = (path: string) => { - const stats = lstatSync(path) - return stats.isDirectory() - } +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], + } + } + } +} const getAllFromDirectory = async (directoryName: string, wantedExtension: string | null = null) => { const fileList: { [p: string]: string } = {} @@ -32,7 +50,7 @@ const getAllFromDirectory = async (directoryName: string, wantedExtension: strin } } return fileList -} + } export default defineConfig({ base: "./", @@ -45,7 +63,7 @@ export default defineConfig({ }, }, }, - plugins: [...getMapsOptimizers(maps)], + plugins: [...getMapsOptimizers(maps, optimizerOptions)], server: { host: "localhost", headers: {