97 lines
3.5 KiB
TypeScript
97 lines
3.5 KiB
TypeScript
// file: Web/game-snake-poc/vite.config.ts
|
|
// version: 3
|
|
|
|
import { NodePackageImporter } from "sass-embedded";
|
|
import { fileURLToPath } from "node:url";
|
|
import { resolve } from "node:path";
|
|
import { defineConfig, normalizePath } from "vite";
|
|
import { viteStaticCopy } from "vite-plugin-static-copy";
|
|
|
|
const appRoot = fileURLToPath(new URL(".", import.meta.url));
|
|
const repositoryRoot = normalizePath(resolve(appRoot, "../.."));
|
|
const frontendRoot = normalizePath(resolve(appRoot, "frontend"));
|
|
const externalBuildRoot = normalizePath(resolve(repositoryRoot, "../builds/sasedev-games/game-snake-poc-web"));
|
|
const wasmRoot = normalizePath(resolve(externalBuildRoot, "wasm"));
|
|
const wasmModule = normalizePath(resolve(wasmRoot, "game_snake_poc_wasm.js"));
|
|
const frontendDist = normalizePath(resolve(externalBuildRoot, "dist"));
|
|
const viteCacheDir = normalizePath(resolve(externalBuildRoot, "vite-cache"));
|
|
const commonRuntimeAsset = normalizePath(resolve(repositoryRoot, "assets/common/data/runtime.json"));
|
|
const gameRuntimeAsset = normalizePath(resolve(repositoryRoot, "assets/game-snake-poc/data/game.json"));
|
|
|
|
export default defineConfig({
|
|
plugins: [
|
|
viteStaticCopy({
|
|
targets: [
|
|
{ src: commonRuntimeAsset, dest: "common/data", rename: { stripBase: true } },
|
|
{ src: gameRuntimeAsset, dest: "game/data", rename: { stripBase: true } },
|
|
],
|
|
}),
|
|
],
|
|
base: "./",
|
|
cacheDir: viteCacheDir,
|
|
clearScreen: false,
|
|
root: frontendRoot,
|
|
publicDir: false,
|
|
input: {
|
|
main: normalizePath(resolve(frontendRoot, "main.html")),
|
|
},
|
|
resolve: {
|
|
alias: {
|
|
"@snake-wasm": wasmModule,
|
|
},
|
|
},
|
|
build: {
|
|
outDir: frontendDist,
|
|
emptyOutDir: true,
|
|
minify: true,
|
|
sourcemap: false,
|
|
cssCodeSplit: true,
|
|
rolldownOptions: {
|
|
output: {
|
|
entryFileNames: "js/[name]-[hash].js",
|
|
chunkFileNames: "js/chunks/[name]-[hash].js",
|
|
assetFileNames: assetInfo => {
|
|
const originalName = assetInfo.names[0] ?? "";
|
|
const extension = originalName.substring(originalName.lastIndexOf(".") + 1).toLowerCase();
|
|
if (extension === "css") {
|
|
return "css/[name]-[hash][extname]";
|
|
}
|
|
if (["eot", "otf", "ttf", "woff", "woff2"].includes(extension)) {
|
|
return "fonts/[name]-[hash][extname]";
|
|
}
|
|
if (["png", "jpg", "jpeg", "gif", "svg", "webp", "ico"].includes(extension)) {
|
|
return "imgs/[name][extname]";
|
|
}
|
|
if (extension === "wasm") {
|
|
return "wasm/[name]-[hash][extname]";
|
|
}
|
|
return "otherassets/[name][extname]";
|
|
},
|
|
},
|
|
},
|
|
},
|
|
css: {
|
|
preprocessorOptions: {
|
|
scss: {
|
|
quietDeps: true,
|
|
silenceDeprecations: ["import", "color-functions", "global-builtin"],
|
|
verbose: false,
|
|
importers: [new NodePackageImporter()],
|
|
},
|
|
},
|
|
},
|
|
server: {
|
|
host: "127.0.0.1",
|
|
port: 1434,
|
|
strictPort: true,
|
|
fs: {
|
|
allow: [appRoot, repositoryRoot, externalBuildRoot],
|
|
},
|
|
},
|
|
preview: {
|
|
host: "127.0.0.1",
|
|
port: 4174,
|
|
strictPort: true,
|
|
},
|
|
});
|