Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

自己编写组件,里面使用微信转发功能,引用本地图片[imageUrl],打包成小程序后,图片放到了 node_modules 里,导致微信小程序不显示图片 #11754

Open
soeasyjx opened this issue May 4, 2022 · 1 comment
Labels
F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x

Comments

@soeasyjx
Copy link

soeasyjx commented May 4, 2022

相关平台

微信小程序

小程序基础库: 2.19.0
使用框架: React

复现步骤

在业务代码中引用,自己开发的组件,打包成微信小程序后,上传到微信小程序,生成体验版

期望结果

正常显示图片,或者能提供其他解决方案也行,改变打包后,图片资源放到 node_modules 文件夹下

自定义组件包目前还没有发布到 npm 上。。

实际结果

小程序转发不显示本地图片

环境信息

👽 Taro v3.4.8

  Taro CLI 3.4.8 environment info:
    System:
      OS: macOS 12.3.1
      Shell: 5.8 - /bin/zsh
    Binaries:
      Node: 14.16.1 - ~/.nvm/versions/node/v14.16.1/bin/node
      Yarn: 1.22.11 - ~/.nvm/versions/node/v14.16.1/bin/yarn
      npm: 6.14.12 - ~/.nvm/versions/node/v14.16.1/bin/npm
    npmPackages:
      @tarojs/cli: 3.4.8 => 3.4.8 
      @tarojs/components: 3.4.8 => 3.4.8 
      @tarojs/mini-runner: 3.4.8 => 3.4.8 
      @tarojs/react: 3.4.8 => 3.4.8 
      @tarojs/runtime: 3.4.8 => 3.4.8 
      @tarojs/taro: 3.4.8 => 3.4.8 
      @tarojs/webpack-runner: 3.4.8 => 3.4.8 
      babel-preset-taro: 3.4.8 => 3.4.8 
      eslint-config-taro: 3.4.8 => 3.4.8 
      react: ^17.0.0 => 17.0.2 
      react-native: ^0.67.3 => 0.67.4 
      taro-ui: ^3.0.0-alpha.3 => 3.0.0-alpha.10 
    npmGlobalPackages:
      typescript: 4.2.4

补充信息

自定义组件,内部部分代码
imageUrl:引用的本地图片 规格为 4kb 1:1

useShareAppMessage((res) => {
   console.log("path", path);

   return {
     title: title,
     imageUrl: thumbImangeUrl ?? require("./icon/60.png"),
     path,
   };
 });

开发组件目录结构:

WX20220504-180233@2x

业务打包生成微信小程序图片目录:

WX20220504-180700@2x

@taro-bot2 taro-bot2 bot added F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x labels May 4, 2022
@yoonzm
Copy link
Contributor

yoonzm commented Sep 2, 2023

解决方案:
在config/index.js增加如下代码

mini: {
  imageUrlLoaderOption: {
    name: (resourcePath) => {
      return resourcePath.replace(path.resolve(__dirname, '..'), '').replace(/node_modules/gi, 'npm')
    },
  },
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x
Projects
None yet
Development

No branches or pull requests

2 participants