fix(admin-web/image-webp): bundle jsquash wasm via vite resolver
Vite 在生产构建里没法解析 @jsquash/webp 自带的相对 wasm 路径,导致 WebP 编码
首次调用就失败。改成直接 import encode.js + ?url 的 wasm 资源,并在 vite.config
里把 specifier 显式 alias 到 node_modules 的真实文件,运行前再调用 init({locateFile})
告诉 wasm 加载器去拿打包后的 URL。
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { createRequire } from "node:module";
|
||||
import { fileURLToPath, URL } from "node:url";
|
||||
|
||||
import vue from "@vitejs/plugin-vue";
|
||||
@@ -6,6 +7,8 @@ import { defineConfig, loadEnv, type PluginOption } from "vite";
|
||||
import { compression } from "vite-plugin-compression2";
|
||||
|
||||
const r = (path: string) => fileURLToPath(new URL(path, import.meta.url));
|
||||
const nodeRequire = createRequire(import.meta.url);
|
||||
const resolveNodeModule = (specifier: string) => nodeRequire.resolve(specifier);
|
||||
|
||||
export default defineConfig(({ mode }) => {
|
||||
const env = loadEnv(mode, ".", "");
|
||||
@@ -42,6 +45,9 @@ export default defineConfig(({ mode }) => {
|
||||
"@": r("./src"),
|
||||
"@geo/shared-types": r("../../packages/shared-types/src/index.ts"),
|
||||
"@geo/http-client": r("../../packages/http-client/src/index.ts"),
|
||||
"@jsquash/webp/encode.js": resolveNodeModule("@jsquash/webp/encode.js"),
|
||||
"@jsquash/webp/codec/enc/webp_enc.wasm": resolveNodeModule("@jsquash/webp/codec/enc/webp_enc.wasm"),
|
||||
"@jsquash/webp/codec/enc/webp_enc_simd.wasm": resolveNodeModule("@jsquash/webp/codec/enc/webp_enc_simd.wasm"),
|
||||
},
|
||||
},
|
||||
server: {
|
||||
|
||||
Reference in New Issue
Block a user