Skip to Content
文档安装

安装

pnpm add react-barcode-scanner

Polyfill

ZBar 为内置依赖,无需额外安装,WASM 约为 230 kB。暂不支持 aztecdata_matrixpdf417;如需扫描这些格式,请使用 ZXing。

import 'react-barcode-scanner/polyfill'
⚠️

ZBar 和 ZXing polyfill 请二选一。浏览器已有原生 BarcodeDetector 时,polyfill 不会覆盖它。

脚手架

Vite

建议使用最新版本的 Vite。如果 Vite 4 或更低版本无法预构建 ESM-only polyfill,可以将上游依赖排除在依赖优化之外:

export default defineConfig({ optimizeDeps: { exclude: ['@preflower/barcode-detector-polyfill'] } })

🙏 感谢 @louispotok  对本章节的帮助

Last updated on