如何从源码重新构建 libheif-bundle.mjs / How to rebuild libheif-bundle.mjs from source ==================================================================================== 二纪没有修改这些组件的源码。下面的步骤只用本目录 source/ 下的源码和公开的免费工具, 可以重新构建出 libheif-bundle.mjs。 二纪 did not modify these components. The steps below use only the archives in source/ and freely available public tools to rebuild libheif-bundle.mjs. 1. 源码 / Sources (./source/) libheif-1.19.8.tar.gz libheif 1.19.8 官方发布包 / official release libde265-1.0.15.tar.gz libde265 1.0.15 官方发布包 / official release libheif-emscripten-1.19.8.tar.gz libheif-emscripten v1.19.8(构建流程 / build pipeline) libheif-js-1.19.8.tar.gz libheif-js 1.19.8(scripts/install.js、scripts/bundle.js) 2. 工具 / Tools (unmodified, general-purpose, publicly available) Emscripten SDK 3.1.61,cmake,make,Node.js, esbuild 0.19.12 与 esbuild-plugins-node-modules-polyfill 1.x(npm)。 3. 编译 WebAssembly / Build the WebAssembly tar xzf source/libheif-1.19.8.tar.gz && cd libheif-1.19.8 cp ../source/libde265-1.0.15.tar.gz . # build-emscripten.sh 直接使用它 / used as-is, no download source /emsdk_env.sh # emsdk install 3.1.61 && emsdk activate 3.1.61 (cd /upstream/emscripten && npm ci) # --emit-tsd 需要 emscripten 自带的 tsc USE_WASM=1 USE_UNSAFE_EVAL=0 ./build-emscripten.sh . # 与 libheif-emscripten v1.19.8 构建流程参数相同 / same parameters as libheif-emscripten v1.19.8 # 结果 / output: libheif.wasm, libheif.js, libheif.d.ts 4. 打包为 libheif-bundle.mjs / Bundle mkdir -p pkg/libheif-wasm && cp libheif.js libheif.wasm libheif.d.ts pkg/libheif-wasm/ && cp COPYING pkg/libheif-wasm/LICENSE (cd pkg && tar czf ../libheif.tar.gz libheif-wasm) tar xzf source/libheif-js-1.19.8.tar.gz && cd libheif-js-1.19.8 npm install esbuild@0.19.12 esbuild-plugins-node-modules-polyfill@^1.6.7 fs-extra@^8.1.0 node-fetch@^2.6.0 rootrequire@^1.0.0 tar-stream@^3.1.6 gunzip-maybe@^1.4.2 # 把 scripts/install.js 中下载 libheif.tar.gz 的地址换成上一步的本地文件,然后: # Point scripts/install.js at the local libheif.tar.gz from the previous step, then: node scripts/install.js # 结果 / output: libheif-wasm/libheif-bundle.mjs 5. 使用修改版 / Use a modified version 修改 libheif 或 libde265 源码后按第 3、4 步构建,得到新的 libheif-bundle.mjs, 再在浏览器中把 /vendor/libheif-js/1.19.8/libheif-bundle.mjs 替换成你的文件(例如开发者工具的本地替换功能)。 After changing libheif or libde265, rebuild with steps 3 and 4 and substitute the file at the fixed URL, e.g. with a browser local override. 接口要求 / Interface: default export is a factory function returning an object with HeifDecoder (decode → images with get_width, get_height, display, free), as in libheif's post.js.