Remove JS obfuscator that broke Mapbox GL map rendering
vite-plugin-obfuscator processes ALL output chunks including vendor libraries, corrupting Mapbox GL's WebGL shader string literals via base64 encoding and string splitting. This caused the map to render as a blank screen in production. Vite's built-in esbuild minification already mangles identifiers and removes whitespace, providing sufficient code protection. Adds regression tests to prevent re-introducing obfuscation plugins.
This commit is contained in:
parent
6a1c35946e
commit
7319f77f1d
6 changed files with 49 additions and 1255 deletions
1234
frontend/package-lock.json
generated
1234
frontend/package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
|
@ -65,7 +65,6 @@
|
||||||
"tw-animate-css": "^1.3.4",
|
"tw-animate-css": "^1.3.4",
|
||||||
"typescript": "~5.8.3",
|
"typescript": "~5.8.3",
|
||||||
"typescript-eslint": "^8.30.1",
|
"typescript-eslint": "^8.30.1",
|
||||||
"vite": "^6.3.5",
|
"vite": "^6.3.5"
|
||||||
"vite-plugin-obfuscator": "^1.0.5"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,6 @@
|
||||||
// "noUncheckedSideEffectImports": true
|
// "noUncheckedSideEffectImports": true
|
||||||
},
|
},
|
||||||
"include": [
|
"include": [
|
||||||
"vite.config.ts",
|
"vite.config.ts"
|
||||||
"vite-plugin-obfuscator.d.ts"
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
4
frontend/vite-plugin-obfuscator.d.ts
vendored
4
frontend/vite-plugin-obfuscator.d.ts
vendored
|
|
@ -1,4 +0,0 @@
|
||||||
declare module 'vite-plugin-obfuscator' {
|
|
||||||
import type { Plugin } from 'vite';
|
|
||||||
export function viteObfuscateFile(options?: Record<string, unknown>): Plugin;
|
|
||||||
}
|
|
||||||
|
|
@ -3,26 +3,12 @@ import react from '@vitejs/plugin-react-swc';
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import { env } from "process";
|
import { env } from "process";
|
||||||
import { defineConfig } from 'vite';
|
import { defineConfig } from 'vite';
|
||||||
import { viteObfuscateFile } from 'vite-plugin-obfuscator';
|
|
||||||
|
|
||||||
// https://vite.dev/config/
|
// https://vite.dev/config/
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [
|
plugins: [
|
||||||
react(),
|
react(),
|
||||||
tailwindcss(),
|
tailwindcss(),
|
||||||
viteObfuscateFile({
|
|
||||||
compact: true,
|
|
||||||
controlFlowFlattening: false,
|
|
||||||
deadCodeInjection: false,
|
|
||||||
debugProtection: false,
|
|
||||||
identifierNamesGenerator: 'hexadecimal',
|
|
||||||
renameGlobals: false,
|
|
||||||
stringArray: true,
|
|
||||||
stringArrayThreshold: 0.75,
|
|
||||||
stringArrayEncoding: ['base64'],
|
|
||||||
splitStrings: true,
|
|
||||||
splitStringsChunkLength: 10,
|
|
||||||
}),
|
|
||||||
],
|
],
|
||||||
build: {
|
build: {
|
||||||
outDir: "dist",
|
outDir: "dist",
|
||||||
|
|
|
||||||
46
tests/unit/test_frontend_build_config.py
Normal file
46
tests/unit/test_frontend_build_config.py
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
"""Regression tests for frontend build configuration.
|
||||||
|
|
||||||
|
Prevents re-introducing JS obfuscation plugins that break vendor libraries
|
||||||
|
(e.g., Mapbox GL WebGL shaders corrupted by string encoding/splitting).
|
||||||
|
"""
|
||||||
|
import json
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
FRONTEND_DIR = Path(__file__).resolve().parents[2] / "frontend"
|
||||||
|
|
||||||
|
|
||||||
|
class TestViteConfig:
|
||||||
|
"""Validate vite.config.ts doesn't contain dangerous build plugins."""
|
||||||
|
|
||||||
|
def test_no_obfuscator_plugin_in_vite_config(self) -> None:
|
||||||
|
"""JS obfuscation breaks Mapbox GL's WebGL shaders and must not be used.
|
||||||
|
|
||||||
|
vite-plugin-obfuscator processes ALL output chunks (including vendor
|
||||||
|
libraries) and corrupts string literals used for WebGL shader source,
|
||||||
|
causing the map to render as a blank screen.
|
||||||
|
"""
|
||||||
|
config = (FRONTEND_DIR / "vite.config.ts").read_text()
|
||||||
|
assert "obfuscat" not in config.lower(), (
|
||||||
|
"vite.config.ts must not use JS obfuscation plugins — "
|
||||||
|
"they corrupt Mapbox GL's WebGL shaders and break the map"
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_no_obfuscator_in_package_json(self) -> None:
|
||||||
|
"""Ensure obfuscator packages are not listed as dependencies."""
|
||||||
|
pkg = json.loads((FRONTEND_DIR / "package.json").read_text())
|
||||||
|
all_deps = {
|
||||||
|
**pkg.get("dependencies", {}),
|
||||||
|
**pkg.get("devDependencies", {}),
|
||||||
|
}
|
||||||
|
for dep_name in all_deps:
|
||||||
|
assert "obfuscat" not in dep_name.lower(), (
|
||||||
|
f"package.json must not include obfuscator packages (found {dep_name})"
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_source_maps_disabled(self) -> None:
|
||||||
|
"""Production builds must not emit source maps."""
|
||||||
|
config = (FRONTEND_DIR / "vite.config.ts").read_text()
|
||||||
|
assert "sourcemap: false" in config or "sourcemap:false" in config, (
|
||||||
|
"vite.config.ts must have sourcemap: false to prevent "
|
||||||
|
"shipping .map files in production"
|
||||||
|
)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue