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

less 图片引用问题 #8581

Open
fengfeng0603 opened this issue Jan 25, 2021 · 1 comment
Open

less 图片引用问题 #8581

fengfeng0603 opened this issue Jan 25, 2021 · 1 comment
Assignees
Labels
F-react Framework - React T-weapp Target - 编译到微信小程序 V-2 Version - 2.x

Comments

@fengfeng0603
Copy link

fengfeng0603 commented Jan 25, 2021

相关平台

微信小程序

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

复现步骤

目前使用taro来适配三端的。
涉及到很多的图片引用, 类似这种。
.img { background-image: url('../../../../img/a.png') }
如果使用alias的话,改为
.img { background-image: url('~assets/img/a.png') }
这种的话,那么H5本地编译没有问题。
小程序中,路径就变为了绝对路径,由于wxss中不能使用本地图片,所以无法显示图片。

如果使用#2334方式提供的方式,在mini postcss-url中配置 basePath,
.img { background-image: url('/assets/img/a.png') }
那么H5编译又会出问题

所以有没有办法,能够在H5 和小程序中做到兼容,同时又能使less中图片引用,变得简洁呢。

期望结果

修复

实际结果

目前 ~ 和 basePath 在less中无法共同使用

环境信息

 Taro CLI 2.2.15 environment info:
    System:
      OS: macOS 10.14.6
      Shell: 5.3 - /bin/zsh
    Binaries:
      Node: 10.16.3 - /usr/local/bin/node
      Yarn: 1.22.4 - /usr/local/bin/yarn
      npm: 6.9.0 - /usr/local/bin/npm
    npmPackages:
      @tarojs/components: 2.2.15 => 2.2.15
      @tarojs/components-qa: 2.2.15 => 2.2.15
      @tarojs/mini-runner: 2.2.15 => 2.2.15
      @tarojs/mobx: 2.2.15 => 2.2.15
      @tarojs/mobx-h5: 2.2.15 => 2.2.15
      @tarojs/mobx-rn: 2.2.15 => 2.2.15
      @tarojs/plugin-less: 2.2.15 => 2.2.15
      @tarojs/plugin-terser: 2.2.15 => 2.2.15
      @tarojs/router: 2.2.15 => 2.2.15
      @tarojs/taro: 2.2.15 => 2.2.15
      @tarojs/taro-alipay: 2.2.15 => 2.2.15
      @tarojs/taro-h5: 2.2.15 => 2.2.15
      @tarojs/taro-qq: 2.2.15 => 2.2.15
      @tarojs/taro-quickapp: 2.2.15 => 2.2.15
      @tarojs/taro-rn: 2.2.15 => 2.2.15
      @tarojs/taro-swan: 2.2.15 => 2.2.15
      @tarojs/taro-tt: 2.2.15 => 2.2.15
      @tarojs/taro-weapp: 2.2.15 => 2.2.15
      @tarojs/webpack-runner: 2.2.15 => 2.2.15
      eslint-config-taro: 2.2.15 => 2.2.15
      eslint-plugin-taro: 2.2.15 => 2.2.15
      nerv-devtools: ^1.5.5 => 1.5.7
      nervjs: ^1.5.5 => 1.5.7
      stylelint-config-taro-rn: 2.2.15 => 2.2.15
      stylelint-taro-rn: 2.2.15 => 2.2.15
    npmGlobalPackages:
      typescript: 3.6.3
@taro-bot2 taro-bot2 bot added F-react Framework - React T-weapp Target - 编译到微信小程序 V-2 Version - 2.x labels Jan 25, 2021
@mideng2
Copy link

mideng2 commented Jan 25, 2021

我也遇到了同样的问题

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-2 Version - 2.x
Projects
None yet
Development

No branches or pull requests

3 participants