taro
taro copied to clipboard
taro怎么引入.wasm或者.wasm.br的文件
相关平台
微信小程序
小程序基础库: 3.3.0 使用框架: Vue 3
复现步骤
页面通过import引入.wasm文件
期望结果
可以正常运行
实际结果
报错
环境信息
Taro CLI 3.6.21 environment info:
System:
OS: macOS 14.2.1
Shell: 5.9 - /bin/zsh
Binaries:
Node: 20.10.0 - /usr/local/bin/node
npm: 10.2.3 - /usr/local/bin/npm
npmPackages:
@tarojs/cli: 3.4.10 => 3.4.10
@tarojs/components: 3.4.10 => 3.4.10
@tarojs/mini-runner: 3.4.10 => 3.4.10
@tarojs/plugin-framework-vue3: 3.4.10 => 3.4.10
@tarojs/plugin-html: 3.4.10 => 3.4.10
@tarojs/runtime: 3.4.10 => 3.4.10
@tarojs/taro: 3.4.10 => 3.4.10
@tarojs/webpack-runner: 3.4.10 => 3.4.10
babel-preset-taro: 3.4.10 => 3.4.10
eslint-config-taro: 3.4.10 => 3.4.10
引入报错
贴一下用法
贴一下用法
import cv from "@/a/js/opencv_exec.js";
原生是可以引入的 https://github.com/sanyuered/WeChat-MiniProgram-AR-WASM/tree/main/package_lesson2
我是react技术栈,希望能对你有所帮助,taro官方文档并没有相关说明。
但是可以曲线**
使用taro混合原生小程序组件
将wasm移动到组件内,
组件js代码(核心代码示例):
import init, { ZipMarker } from './pkg/rust_zip';
Component({});
export default {
init: async (input) => {
await init(input);
},
ZipMarker,
};
使用的页面
export default definePageConfig({
usingComponents: {
'g-zip': '../../components/g-zip',
},
});
config/index.js改动
copy: {
patterns: [
{
from: 'src/pages/components/g-zip/pkg/',
//这里移动到打包后对应应该存放的位置
to: `dist/${process.env.TARO_ENV || 'app'}/pages/components/g-zip/pkg/`,
ignore: ['*.js', '*.scss'],
},
],
},
........
webpackChain(chain) {
chain.merge({
module: {
rule: {
'wasm-loader': {
test: /\.wasm$/,
use: [
{
loader: 'wasm-loader',
},
],
},
},
},
});
},
使用:
import zipWasm from './../../components/g-zip/index';
// 打包对应后的位置
zipWasm.init('pages/components/g-zip/pkg/rust_zip_bg.wasm');